Ejemplo n.º 1
0
    FieldInjectProgram(Field field, InjectionPoint ip) {
      _field = field;
      _field.setAccessible(true);
      _ip = ip;

      InjectManager beanManager = getBeanManager();

      try {
        _fieldFactory = beanManager.getReferenceFactory(_ip);
      } catch (AmbiguousResolutionException e) {
        String loc = getLocation(field);

        throw new AmbiguousResolutionException(loc + e.getMessage(), e);
      } catch (UnsatisfiedResolutionException e) {
        String loc = getLocation(field);

        throw new UnsatisfiedResolutionException(loc + e.getMessage(), e);
      } catch (IllegalProductException e) {
        String loc = getLocation(field);

        throw new IllegalProductException(loc + e.getMessage(), e);
      } catch (InjectionException e) {
        String loc = getLocation(field);

        throw new InjectionException(loc + e.getMessage(), e);
      }
    }
Ejemplo n.º 2
0
    @Override
    public <T> void inject(T instance, CreationalContext<T> cxt) {
      try {
        CreationalContextImpl<?> env;

        if (cxt instanceof CreationalContextImpl<?>) env = (CreationalContextImpl<?>) cxt;
        else env = null;

        // server/30i1 vs ioc/0155
        Object value = _fieldFactory.create(null, env, _ip);

        _field.set(instance, value);
      } catch (AmbiguousResolutionException e) {
        throw new AmbiguousResolutionException(getFieldName(_field) + e.getMessage(), e);
      } catch (IllegalProductException e) {
        throw new IllegalProductException(getFieldName(_field) + e.getMessage(), e);
      } catch (InjectionException e) {
        throw new InjectionException(getFieldName(_field) + e.getMessage(), e);
      } catch (Exception e) {
        throw ConfigException.create(_field, e);
      }
    }