Beispiel #1
0
 protected void initEnhancedSubclass() {
   final ClassTransformer transformer = beanManager.getServices().get(ClassTransformer.class);
   enhancedSubclass = transformer.loadClass(createEnhancedSubclass());
   constructorForEnhancedSubclass =
       WeldConstructorImpl.of(
           enhancedSubclass.getDeclaredWeldConstructor(getConstructor().getSignature()),
           enhancedSubclass,
           transformer);
 }
  @Override
  protected void storeSyntheticAnnotatedType(
      BeanDeployment deployment, AnnotatedType<?> type, String id) {
    SlimAnnotatedType<?> annotatedType =
        transformer.getUnbackedAnnotatedType(type, getBeanManager().getId(), id);
    Extension extension = getReceiver();
    SlimAnnotatedTypeContext<?> annotatedTypeContext =
        SlimAnnotatedTypeContext.of(annotatedType, extension);

    ProcessAnnotatedTypeImpl<?> event =
        events.fireProcessAnnotatedType(getBeanManager(), annotatedTypeContext);
    if (event == null) {
      deployment.getBeanDeployer().getEnvironment().addAnnotatedType(annotatedTypeContext);
      store.put(annotatedType);
    } else if (event.isVeto()) {
      return;
    } else {
      annotatedType = event.getResultingAnnotatedType();
      deployment
          .getBeanDeployer()
          .getEnvironment()
          .addSyntheticAnnotatedType(annotatedType, extension);
      store.put(annotatedType);
    }
  }
 /**
  * Call this method after all observer methods of this event have been invoked to get the final
  * value of this {@link AnnotatedType}.
  *
  * @return the resulting annotated type
  */
 public SlimAnnotatedType<X> getResultingAnnotatedType() {
   if (isDirty()) {
     return ClassTransformer.instance(manager)
         .getUnbackedAnnotatedType(originalAnnotatedType, annotatedType);
   } else {
     return originalAnnotatedType;
   }
 }
  public ExtensionBeanDeployer deployBeans() {
    ClassTransformer classTransformer =
        Container.instance().deploymentServices().get(ClassTransformer.class);
    for (Extension extension : extensions) {
      @SuppressWarnings("unchecked")
      WeldClass<Extension> clazz =
          (WeldClass<Extension>) classTransformer.loadClass(extension.getClass());

      // Locate the BeanDeployment for this extension
      BeanDeployment beanDeployment =
          DeploymentStructures.getOrCreateBeanDeployment(
              deployment, beanManager, beanDeployments, clazz.getJavaClass());

      ExtensionBean bean = new ExtensionBean(beanDeployment.getBeanManager(), clazz, extension);
      Set<ObserverMethodImpl<?, ?>> observerMethods = new HashSet<ObserverMethodImpl<?, ?>>();
      createObserverMethods(bean, beanDeployment.getBeanManager(), clazz, observerMethods);
      beanDeployment.getBeanManager().addBean(bean);
      for (ObserverMethodImpl<?, ?> observerMethod : observerMethods) {
        observerMethod.initialize();
        beanDeployment.getBeanManager().addObserver(observerMethod);
      }
    }
    return this;
  }
  /**
   * Constructor
   *
   * <p>Also builds the meta-annotation map. Throws a NullPointerException if trying to register a
   * null map
   *
   * @param annotationMap A map of annotation to register
   */
  public AbstractWeldAnnotated(
      Map<Class<? extends Annotation>, Annotation> annotationMap,
      Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap,
      ClassTransformer classTransformer,
      Class<T> rawType,
      Type type,
      Set<Type> typeClosure) {
    if (annotationMap == null) {
      throw new WeldException(ANNOTATION_MAP_NULL);
    }
    this.annotationMap = annotationMap;
    this.metaAnnotationMap = new ArraySetMultimap<Class<? extends Annotation>, Annotation>();
    for (Annotation annotation : annotationMap.values()) {
      addMetaAnnotations(
          metaAnnotationMap, annotation, annotation.annotationType().getAnnotations(), false);
      addMetaAnnotations(
          metaAnnotationMap,
          annotation,
          classTransformer.getTypeStore().get(annotation.annotationType()),
          false);
    }
    metaAnnotationMap.trimToSize();

    if (declaredAnnotationMap == null) {
      throw new WeldException(DECLARED_ANNOTATION_MAP_NULL);
    }
    this.rawType = rawType;
    this.type = type;
    if (type instanceof ParameterizedType) {
      this.actualTypeArguments = ((ParameterizedType) type).getActualTypeArguments();
    } else {
      this.actualTypeArguments = new Type[0];
    }
    this.typeClosure = Collections.unmodifiableSet(new ArraySet<Type>(typeClosure));
    this.proxyable = Proxies.isTypesProxyable(typeClosure);
  }