예제 #1
0
파일: Validator.java 프로젝트: edpzjh/core
 private void validateDecorators(BeanManagerImpl beanManager, AbstractClassBean<?> classBean) {
   if (classBean.getDecorators().size() > 0) {
     boolean passivationCapabilityCheckRequired =
         isPassivationCapabilityCheckRequired(beanManager, classBean);
     for (Decorator<?> decorator : classBean.getDecorators()) {
       if (passivationCapabilityCheckRequired) {
         boolean isSerializable =
             (decorator instanceof WeldDecorator<?>)
                 ? (((WeldDecorator<?>) decorator).getWeldAnnotated().isSerializable())
                 : (decorator instanceof PassivationCapable);
         if (!isSerializable) {
           throw new UnserializableDependencyException(
               PASSIVATING_BEAN_WITH_NONSERIALIZABLE_DECORATOR, classBean, decorator);
         }
       }
       for (InjectionPoint ij : decorator.getInjectionPoints()) {
         if (!ij.isDelegate()) {
           Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij));
           validateInjectionPoint(ij, beanManager);
           if (passivationCapabilityCheckRequired) {
             validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
           }
         }
       }
     }
   }
 }
예제 #2
0
  public static Object[] generateProxyDelegate(
      InjectManager manager,
      List<Decorator<?>> beans,
      Object delegateProxy,
      CreationalContextImpl<?> parentEnv) {
    Object[] instances = new Object[beans.size()];

    DependentCreationalContext<Object> proxyEnv =
        new DependentCreationalContext<Object>(DelegateProxyBean.BEAN, parentEnv, null);

    proxyEnv.push(delegateProxy);

    for (int i = 0; i < beans.size(); i++) {
      Decorator<?> bean = beans.get(i);

      CreationalContextImpl<?> env = new DependentCreationalContext(bean, proxyEnv, null);

      Object instance = manager.getReference(bean, bean.getBeanClass(), env);

      // XXX:
      InjectionPoint ip = getDelegate(bean);

      if (ip.getMember() instanceof Field) {
        Field field = (Field) ip.getMember();
        field.setAccessible(true);

        try {
          field.set(instance, delegateProxy);
        } catch (Exception e) {
          throw new InjectionException(e);
        }
      } else if (ip.getMember() instanceof Method) {
        Method method = (Method) ip.getMember();
        method.setAccessible(true);

        try {
          method.invoke(instance, delegateProxy);
        } catch (Exception e) {
          throw new InjectionException(e);
        }
      }

      /*
      DecoratorBean<?> decoratorBean = (DecoratorBean<?>) bean;
      decoratorBean.setDelegate(instance, proxy);
      */

      instances[beans.size() - i - 1] = instance;

      if (parentEnv instanceof CreationalContextImpl<?>) {
        // InjectionPoint ip = decoratorBean.getDelegateInjectionPoint();

        ((CreationalContextImpl<?>) parentEnv).setInjectionPoint(ip);
      }
    }

    return instances;
  }
 private void validateDecorator(Decorator<?> decorator) {
   Set<Annotation> qualifiers = decorator.getDelegateQualifiers();
   if (decorator.getDelegateType() == null) {
     throw BeanLogger.LOG.decoratorMethodReturnsNull("getDelegateType", decorator);
   }
   Bindings.validateQualifiers(
       qualifiers, getBeanManager(), decorator, "Decorator.getDelegateQualifiers");
   if (decorator.getDecoratedTypes() == null) {
     throw BeanLogger.LOG.decoratorMethodReturnsNull("getDecoratedTypes", decorator);
   }
 }
예제 #4
0
파일: Validator.java 프로젝트: edpzjh/core
 private void validateEnabledDecoratorClasses(BeanManagerImpl beanManager) {
   // TODO Move building this list to the boot or sth
   Set<Class<?>> decoratorBeanClasses = new HashSet<Class<?>>();
   for (Decorator<?> bean : beanManager.getAccessibleDecorators()) {
     decoratorBeanClasses.add(bean.getBeanClass());
   }
   for (Metadata<Class<?>> clazz : beanManager.getEnabled().getDecorators()) {
     if (!decoratorBeanClasses.contains(clazz.getValue())) {
       throw new DeploymentException(
           DECORATOR_CLASS_NOT_BEAN_CLASS_OF_DECORATOR, clazz, decoratorBeanClasses);
     }
   }
 }
 @Test(groups = INTEGRATION)
 @SpecAssertions({
   @SpecAssertion(section = DECORATOR_INVOCATION, id = "acj"),
   @SpecAssertion(section = DECORATOR_RESOLUTION, id = "aa")
 })
 public void testDecoratorIsResolved() {
   List<Decorator<?>> decorators =
       getCurrentManager().resolveDecorators(Collections.<Type>singleton(HttpSession.class));
   assertEquals(2, decorators.size());
   for (Decorator<?> decorator : decorators) {
     assertEquals(decorator.getDecoratedTypes(), Collections.<Type>singleton(HttpSession.class));
     assertEquals(decorator.getDelegateType(), HttpSession.class);
   }
 }
예제 #6
0
  private static InjectionPoint getDelegate(Decorator<?> bean) {
    if (bean instanceof DecoratorBean) return ((DecoratorBean) bean).getDelegateInjectionPoint();

    for (InjectionPoint ip : bean.getInjectionPoints()) {
      if (ip.isDelegate()) return ip;
    }

    throw new IllegalStateException(String.valueOf(bean));
  }
예제 #7
0
  public static Method[] createDecoratorMethods(
      List<Decorator<?>> decorators, String methodName, Class<?>... paramTypes) {
    Method[] methods = new Method[decorators.size()];

    for (int i = 0; i < decorators.size(); i++) {
      Decorator<?> decorator = decorators.get(i);
      Class<?> beanClass = decorator.getBeanClass();

      try {
        methods[decorators.size() - i - 1] = beanClass.getMethod(methodName, paramTypes);
        methods[decorators.size() - i - 1].setAccessible(true);
      } catch (Exception e) {
        log.log(Level.FINEST, e.toString(), e);
      }
    }

    return methods;
  }
  public static Object generateDelegate(List<Decorator> beans, Object tail) {
    InjectManager webBeans = InjectManager.create();

    Bean parentBean = null;
    CreationalContext env = webBeans.createCreationalContext(parentBean);

    for (int i = beans.size() - 1; i >= 0; i--) {
      Decorator bean = beans.get(i);

      Object instance = webBeans.getReference(bean, bean.getBeanClass(), env);

      // XXX:
      // bean.setDelegate(instance, tail);

      tail = instance;
    }

    return tail;
  }
  public static Object[] generateProxyDelegate(
      InjectManager webBeans, List<Decorator<?>> beans, Object proxy) {
    Object[] instances = new Object[beans.size()];

    Bean parentBean = null;
    CreationalContext env = webBeans.createCreationalContext(parentBean);

    for (int i = 0; i < beans.size(); i++) {
      Decorator bean = beans.get(i);

      Object instance = webBeans.getReference(bean, bean.getBeanClass(), env);

      // XXX:
      ((DecoratorBean) bean).setDelegate(instance, proxy);

      instances[beans.size() - 1 - i] = instance;
    }

    return instances;
  }