Esempio n. 1
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;
  }
Esempio n. 2
0
 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);
     }
   }
 }
Esempio n. 3
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;
  }