/**
   * Check the deployment annotation index for all classes with the @PersistenceContext annotation.
   * For each class with the annotation, collect all the required information to create a managed
   * bean instance, and attach it to the context.
   *
   * @param phaseContext the deployment unit context
   * @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException
   */
  protected void processComponentConfig(
      final DeploymentUnit deploymentUnit,
      final DeploymentPhaseContext phaseContext,
      final CompositeIndex compositeIndex,
      final AbstractComponentDescription componentDescription)
      throws DeploymentUnitProcessingException {

    final ClassInfo classInfo =
        compositeIndex.getClassByName(
            DotName.createSimple(componentDescription.getComponentClassName()));
    if (classInfo == null) {
      return; // We can't continue without the annotation index info.
    }
    componentDescription
        .getBindings()
        .addAll(getConfigurations(deploymentUnit, classInfo, componentDescription, phaseContext));
    final Collection<InterceptorDescription> interceptorConfigurations =
        componentDescription.getAllInterceptors().values();
    for (InterceptorDescription interceptorConfiguration : interceptorConfigurations) {
      final ClassInfo interceptorClassInfo =
          compositeIndex.getClassByName(
              DotName.createSimple(interceptorConfiguration.getInterceptorClassName()));
      if (interceptorClassInfo == null) {
        continue;
      }
      interceptorConfiguration
          .getBindings()
          .addAll(
              getConfigurations(
                  deploymentUnit, interceptorClassInfo, componentDescription, phaseContext));
    }
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription eeModuleDescription =
        deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final CompositeIndex index =
        deploymentUnit.getAttachment(
            org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    final EEApplicationClasses applicationClasses =
        deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);

    // @PersistenceContext
    List<AnnotationInstance> persistenceContexts =
        index.getAnnotations(PERSISTENCE_CONTEXT_ANNOTATION_NAME);
    // create binding and injection configurations out of the @PersistenceContext annotations
    this.processPersistenceAnnotations(
        deploymentUnit, eeModuleDescription, persistenceContexts, applicationClasses);

    // @PersistenceUnit
    List<AnnotationInstance> persistenceUnits =
        index.getAnnotations(PERSISTENCE_UNIT_ANNOTATION_NAME);
    // create binding and injection configurations out of the @PersistenceUnit annotaitons
    this.processPersistenceAnnotations(
        deploymentUnit, eeModuleDescription, persistenceUnits, applicationClasses);

    // if we found any @PersistenceContext or @PersistenceUnit annotations then mark this as a JPA
    // deployment
    if (!persistenceContexts.isEmpty() || !persistenceUnits.isEmpty()) {
      JPADeploymentMarker.mark(deploymentUnit);
    }
  }
  /**
   * Check the deployment annotation index for all classes with the @ManagedBean annotation. For
   * each class with the annotation, collect all the required information to create a managed bean
   * instance, and attach it to the context.
   *
   * @param phaseContext the deployment unit context
   * @throws DeploymentUnitProcessingException
   */
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription =
        deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final String applicationName = moduleDescription.getAppName();
    final CompositeIndex compositeIndex =
        deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
      return;
    }
    final List<AnnotationInstance> instances =
        compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME);
    if (instances == null || instances.isEmpty()) {
      return;
    }

    for (AnnotationInstance instance : instances) {
      AnnotationTarget target = instance.target();
      if (!(target instanceof ClassInfo)) {
        throw new DeploymentUnitProcessingException(
            "The ManagedBean annotation is only allowed at the class level: " + target);
      }
      final ClassInfo classInfo = (ClassInfo) target;
      final String beanClassName = classInfo.name().toString();

      // Get the managed bean name from the annotation
      final AnnotationValue nameValue = instance.value();
      final String beanName =
          nameValue == null || nameValue.asString().isEmpty()
              ? beanClassName
              : nameValue.asString();
      final ManagedBeanComponentDescription componentDescription =
          new ManagedBeanComponentDescription(
              beanName, beanClassName, moduleDescription.getModuleName(), applicationName);
      final ServiceName baseName =
          deploymentUnit.getServiceName().append("component").append(beanName);

      // Add the view
      componentDescription.getViewClassNames().add(beanClassName);

      // Bind the view to its two JNDI locations
      // TODO - this should be a bit more elegant
      final BindingDescription moduleBinding = new BindingDescription();
      moduleBinding.setAbsoluteBinding(true);
      moduleBinding.setBindingName("java:module/" + beanName);
      moduleBinding.setBindingType(beanClassName);
      moduleBinding.setReferenceSourceDescription(
          new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName)));
      componentDescription.getBindings().add(moduleBinding);
      final BindingDescription appBinding = new BindingDescription();
      appBinding.setAbsoluteBinding(true);
      appBinding.setBindingName("java:app/" + moduleDescription.getModuleName() + "/" + beanName);
      appBinding.setBindingType(beanClassName);
      appBinding.setReferenceSourceDescription(
          new ServiceBindingSourceDescription(baseName.append("VIEW").append(beanClassName)));
      componentDescription.getBindings().add(appBinding);
      moduleDescription.addComponent(componentDescription);
    }
  }
  public void deploy(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    final Map<Class<? extends Annotation>, Set<Class<?>>> instances =
        new HashMap<Class<? extends Annotation>, Set<Class<?>>>();

    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 ClassLoader classLoader = module.getClassLoader();

    for (FacesAnnotation annotation : FacesAnnotation.values()) {
      final List<AnnotationInstance> annotationInstances =
          compositeIndex.getAnnotations(annotation.indexName);
      if (annotationInstances == null || annotationInstances.isEmpty()) {
        continue;
      }
      final Set<Class<?>> discoveredClasses = new HashSet<Class<?>>();
      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(
                JSFMessages.MESSAGES.classLoadingFailed(className));
          }
          discoveredClasses.add(annotatedClass);
        } else {
          throw new DeploymentUnitProcessingException(
              JSFMessages.MESSAGES.invalidAnnotationLocation(annotation, target));
        }
      }
    }
    deploymentUnit.addToAttachmentList(
        ServletContextAttribute.ATTACHMENT_KEY,
        new ServletContextAttribute(FACES_ANNOTATIONS_SC_ATTR, instances));
  }
  private String getMessageListenerInterface(
      final CompositeIndex compositeIndex, final AnnotationInstance messageBeanAnnotation)
      throws DeploymentUnitProcessingException {
    final AnnotationValue value = messageBeanAnnotation.value("messageListenerInterface");
    if (value != null) return value.asClass().name().toString();
    final ClassInfo beanClass = (ClassInfo) messageBeanAnnotation.target();
    final Set<DotName> interfaces = new HashSet<DotName>(getPotentialViewInterfaces(beanClass));
    // check super class(es) of the bean
    DotName superClassDotName = beanClass.superName();
    while (interfaces.isEmpty()
        && superClassDotName != null
        && !superClassDotName.toString().equals(Object.class.getName())) {
      final ClassInfo superClass = compositeIndex.getClassByName(superClassDotName);
      if (superClass == null) {
        break;
      }
      interfaces.addAll(getPotentialViewInterfaces(superClass));
      // move to next super class
      superClassDotName = superClass.superName();
    }

    if (interfaces.size() != 1)
      throw MESSAGES.mdbDoesNotImplementNorSpecifyMessageListener(beanClass);
    return interfaces.iterator().next().toString();
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    final CompositeIndex index =
        deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);

    for (final JaxrsAnnotations annotation : JaxrsAnnotations.values()) {
      if (!index.getAnnotations(annotation.getDotName()).isEmpty()) {
        JaxrsDeploymentMarker.mark(deploymentUnit);
        phaseContext.addToAttachmentList(
            Attachments.NEXT_PHASE_DEPS, Services.JBOSS_MODULE_INDEX_SERVICE);
        return;
      }
    }
  }
Beispiel #7
0
 public static boolean isJaxwsService(final ClassInfo current, final CompositeIndex index) {
   ClassInfo tmp = current;
   while (tmp != null) {
     final DotName superName = tmp.superName();
     if (JAXWS_SERVICE_CLASS.equals(superName)) {
       return true;
     }
     tmp = index.getClassByName(superName);
   }
   return false;
 }
  @Override
  protected void processAnnotations(DeploymentUnit deploymentUnit, CompositeIndex compositeIndex)
      throws DeploymentUnitProcessingException {
    if (MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
      return;
    }

    processMessageBeans(
        deploymentUnit,
        compositeIndex.getAnnotations(MESSAGE_DRIVEN_ANNOTATION_NAME),
        compositeIndex);
  }
  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);

    for (AnnotationInstance annotation : resourceAnnotations) {
      final AnnotationTarget annotationTarget = annotation.target();
      final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(annotation);
      if (annotationTarget instanceof FieldInfo) {
        processField(
            deploymentUnit, annotationWrapper, (FieldInfo) annotationTarget, moduleDescription);
      } else if (annotationTarget instanceof MethodInfo) {
        processMethod(
            deploymentUnit, annotationWrapper, (MethodInfo) annotationTarget, moduleDescription);
      } else if (annotationTarget instanceof ClassInfo) {
        processClass(
            deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
      }
    }
    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);
          processClass(
              deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
        }
      } else {
        throw MESSAGES.annotationOnlyAllowedOnClass(EJBs.class.getName(), annotation.target());
      }
    }
  }
 private Set<ClassInfo> processHandlesType(DotName typeName, Class<?> type, CompositeIndex index)
     throws DeploymentUnitProcessingException {
   Set<ClassInfo> classes = new HashSet<ClassInfo>();
   if (type.isAnnotation()) {
     List<AnnotationInstance> instances = index.getAnnotations(typeName);
     for (AnnotationInstance instance : instances) {
       AnnotationTarget annotationTarget = instance.target();
       if (annotationTarget instanceof ClassInfo) {
         classes.add((ClassInfo) annotationTarget);
       } else if (annotationTarget instanceof FieldInfo) {
         classes.add(((FieldInfo) annotationTarget).declaringClass());
       } else if (annotationTarget instanceof MethodInfo) {
         classes.add(((MethodInfo) annotationTarget).declaringClass());
       } else if (annotationTarget instanceof MethodParameterInfo) {
         classes.add(((MethodParameterInfo) annotationTarget).method().declaringClass());
       }
     }
   } else {
     classes.addAll(index.getAllKnownSubclasses(typeName));
     classes.addAll(index.getAllKnownImplementors(typeName));
   }
   return classes;
 }
  /** Process annotations and merge any available metadata at the same time. */
  @Override
  protected void processAnnotations(
      final DeploymentUnit deploymentUnit, final CompositeIndex compositeIndex)
      throws DeploymentUnitProcessingException {

    if (MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
      return;
    }

    // Find and process any @Stateless bean annotations
    final List<AnnotationInstance> slsbAnnotations =
        compositeIndex.getAnnotations(STATELESS_ANNOTATION);
    if (!slsbAnnotations.isEmpty()) {
      processSessionBeans(
          deploymentUnit,
          slsbAnnotations,
          SessionBeanComponentDescription.SessionBeanType.STATELESS);
    }

    // Find and process any @Stateful bean annotations
    final List<AnnotationInstance> sfsbAnnotations =
        compositeIndex.getAnnotations(STATEFUL_ANNOTATION);
    if (!sfsbAnnotations.isEmpty()) {
      processSessionBeans(
          deploymentUnit,
          sfsbAnnotations,
          SessionBeanComponentDescription.SessionBeanType.STATEFUL);
    }

    // Find and process any @Singleton bean annotations
    final List<AnnotationInstance> sbAnnotations =
        compositeIndex.getAnnotations(SINGLETON_ANNOTATION);
    if (!sbAnnotations.isEmpty()) {
      processSessionBeans(
          deploymentUnit, sbAnnotations, SessionBeanComponentDescription.SessionBeanType.SINGLETON);
    }
  }
 private SessionType determineSessionType(
     final String ejbClass, final CompositeIndex compositeIndex) {
   if (ejbClass == null) {
     return null;
   }
   final ClassInfo info = compositeIndex.getClassByName(DotName.createSimple(ejbClass));
   if (info == null) {
     return null;
   }
   if (info.annotations().get(STATEFUL_ANNOTATION) != null) {
     return SessionType.Stateful;
   } else if (info.annotations().get(STATELESS_ANNOTATION) != null) {
     return SessionType.Stateless;
   } else if (info.annotations().get(SINGLETON_ANNOTATION) != null) {
     return SessionType.Singleton;
   }
   return null;
 }
  protected void scan(
      final DeploymentUnit du,
      final ClassLoader classLoader,
      final ResteasyDeploymentData resteasyDeploymentData)
      throws DeploymentUnitProcessingException, ModuleLoadException {

    final CompositeIndex index = du.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);

    if (!resteasyDeploymentData.shouldScan()) {
      return;
    }

    final Set<ClassInfo> applicationClass = index.getAllKnownSubclasses(APPLICATION);
    try {
      if (applicationClass.size() > 1) {
        StringBuilder builder = new StringBuilder();
        Set<ClassInfo> aClasses = new HashSet<ClassInfo>();
        for (ClassInfo c : applicationClass) {
          if (!Modifier.isAbstract(c.flags())) {
            aClasses.add(c);
          }
          builder.append(" ").append(c.name().toString());
        }
        if (aClasses.size() > 1) {
          throw new DeploymentUnitProcessingException(
              MESSAGES.onlyOneApplicationClassAllowed(builder));
        } else if (aClasses.size() == 1) {
          ClassInfo aClass = applicationClass.iterator().next();
          resteasyDeploymentData.setScannedApplicationClass(
              (Class<? extends Application>) classLoader.loadClass(aClass.name().toString()));
        }
      } else if (applicationClass.size() == 1) {
        ClassInfo aClass = applicationClass.iterator().next();
        resteasyDeploymentData.setScannedApplicationClass(
            (Class<? extends Application>) classLoader.loadClass(aClass.name().toString()));
      }
    } catch (ClassNotFoundException e) {
      throw MESSAGES.cannotLoadApplicationClass(e);
    }

    List<AnnotationInstance> resources = null;
    List<AnnotationInstance> providers = null;
    if (resteasyDeploymentData.isScanResources()) {
      resources = index.getAnnotations(JaxrsAnnotations.PATH.getDotName());
    }
    if (resteasyDeploymentData.isScanProviders()) {
      providers = index.getAnnotations(JaxrsAnnotations.PROVIDER.getDotName());
    }

    if ((resources == null || resources.isEmpty()) && (providers == null || providers.isEmpty()))
      return;
    final Set<ClassInfo> pathInterfaces = new HashSet<ClassInfo>();
    if (resources != null) {
      for (AnnotationInstance e : resources) {
        final ClassInfo info;
        if (e.target() instanceof ClassInfo) {
          info = (ClassInfo) e.target();
        } else if (e.target() instanceof MethodInfo) {
          // ignore
          continue;
        } else {
          JAXRS_LOGGER.classOrMethodAnnotationNotFound("@Path", e.target());
          continue;
        }
        if (!Modifier.isInterface(info.flags())) {
          resteasyDeploymentData.getScannedResourceClasses().add(info.name().toString());
        } else {
          pathInterfaces.add(info);
        }
      }
    }
    if (providers != null) {
      for (AnnotationInstance e : providers) {
        if (e.target() instanceof ClassInfo) {
          ClassInfo info = (ClassInfo) e.target();
          if (!Modifier.isInterface(info.flags())) {
            resteasyDeploymentData.getScannedProviderClasses().add(info.name().toString());
          }
        } else {
          JAXRS_LOGGER.classAnnotationNotFound("@Provider", e.target());
        }
      }
    }

    // look for all implementations of interfaces annotated @Path
    for (final ClassInfo iface : pathInterfaces) {
      final Set<ClassInfo> implementors = index.getAllKnownImplementors(iface.name());
      for (final ClassInfo implementor : implementors) {
        resteasyDeploymentData.getScannedResourceClasses().add(implementor.name().toString());
      }
    }
  }
Beispiel #14
0
 public static List<AnnotationInstance> getAnnotations(
     final DeploymentUnit unit, final DotName annotation) {
   final CompositeIndex compositeIndex =
       getRequiredAttachment(unit, Attachments.COMPOSITE_ANNOTATION_INDEX);
   return compositeIndex.getAnnotations(annotation);
 }