Esempio n. 1
0
  @Override
  public void bind(Resolution resolution) throws BindingException {
    builderInfo =
        new AssociationInfo() {
          @Override
          public boolean isImmutable() {
            return false;
          }

          @Override
          public QualifiedName qualifiedName() {
            return qualifiedName;
          }

          @Override
          public Type type() {
            return type;
          }

          @Override
          public void checkConstraints(Object value) throws ConstraintViolationException {
            AssociationModel.this.checkConstraints(value);
          }
        };

    if (type instanceof TypeVariable) {

      Class mainType = first(resolution.model().types());
      type =
          Classes.resolveTypeVariable(
              (TypeVariable) type, ((Member) accessor).getDeclaringClass(), mainType);
    }
  }
Esempio n. 2
0
  public void bind(Resolution resolution) throws BindingException {
    boundConstructors = new ArrayList<ConstructorModel>();
    for (ConstructorModel constructorModel : constructorModels) {
      try {
        constructorModel.bind(resolution);
        boundConstructors.add(constructorModel);
      } catch (Exception e) {
        // Ignore
        e.printStackTrace();
      }
    }

    if (boundConstructors.size() == 0) {
      StringBuilder messageBuilder =
          new StringBuilder("Found no constructor that could be bound: ");
      if (resolution.object() instanceof AbstractCompositeDescriptor) {
        messageBuilder
            .append(fragmentClass.getName())
            .append(" in ")
            .append(resolution.object().toString());
      } else {
        messageBuilder.append(resolution.object().toString());
      }

      if (messageBuilder.indexOf("$") >= 0) {
        messageBuilder.append("\nNon-static inner classes can not be used.");
      }

      String message = messageBuilder.toString();
      throw new BindingException(message);
    }

    // Sort based on parameter count
    Collections.sort(
        boundConstructors,
        new Comparator<ConstructorModel>() {
          public int compare(ConstructorModel o1, ConstructorModel o2) {
            Integer model2ParametersCount = o2.constructor().getParameterTypes().length;
            int model1ParametersCount = o1.constructor().getParameterTypes().length;
            return model2ParametersCount.compareTo(model1ParametersCount);
          }
        });
  }
Esempio n. 3
0
  public void bind(Resolution resolution) throws BindingException {
    InjectionProviderFactory providerFactory = resolution.application().injectionProviderFactory();

    try {
      injectionProvider = providerFactory.newInjectionProvider(resolution, this);

      if (injectionProvider == null && !optional) {
        String message =
            "Non-optional @"
                + rawInjectionClass.getName()
                + " was not bound in "
                + injectedClass.getName();
        throw new ConstructionException(message);
      }
    } catch (InvalidInjectionException e) {
      throw new BindingException("Could not bind dependency injection", e);
    }
  }