Package com.google.inject

Examples of com.google.inject.PrivateBinder


              return null;
            }

            void rewrite(Binder binder, PrivateElements privateElements, Set<Key<?>> keysToSkip) {
              PrivateBinder privateBinder = binder.withSource(privateElements.getSource())
                  .newPrivateBinder();

              Set<Key<?>> skippedExposes = Sets.newHashSet();

              for (Key<?> key : privateElements.getExposedKeys()) {
                if (keysToSkip.remove(key)) {
                  skippedExposes.add(key);
                } else {
                  privateBinder.withSource(privateElements.getExposedSource(key)).expose(key);
                }
              }

              for (Element element : privateElements.getElements()) {
                if (element instanceof Binding
View Full Code Here


  /**
   * Writes the elements of the private environment to a new private binder and {@link
   * #setPrivateBinder associates} the two.
   */
  protected void writePrivateElements(Binder binder, PrivateElements element) {
    PrivateBinder privateBinder = binder.withSource(element.getSource()).newPrivateBinder();
    setPrivateBinder(element, privateBinder);
    apply(privateBinder, element.getElements());
    for (Key<?> key : element.getExposedKeys()) {
      privateBinder.withSource(element.getExposedSource(key)).expose(key);
    }
  }
View Full Code Here

  /**
   * Returns the {@code binder} accociated with {@code privateElements}. This can be used to
   * expose bindings to the enclosing environment.
   */
  protected PrivateBinder getPrivateBinder(PrivateElements privateElements) {
    PrivateBinder privateBinder = environmentToBinder.get(privateElements);
    checkArgument(privateBinder != null, "No private binder for %s", privateElements);
    return privateBinder;
  }
View Full Code Here

  /**
   * Writes the elements of the private environment to a new private binder and {@link
   * #setPrivateBinder associates} the two.
   */
  protected void writePrivateElements(Binder binder, PrivateElements element) {
    PrivateBinder privateBinder = binder.withSource(element.getSource()).newPrivateBinder();
    setPrivateBinder(element, privateBinder);
    apply(privateBinder, element.getElements());
  }
View Full Code Here

      public ScopedBindingBuilder visitUntargetted(UntargettedBinding<? extends T> binding) {
        return binder.bind(key);
      }

      public ScopedBindingBuilder visitExposed(ExposedBinding<? extends T> binding) {
        PrivateBinder privateBinder = getPrivateBinder(binding.getPrivateElements());
        privateBinder.withSource(binding.getSource()).expose(key);
        return null;
      }

      public ScopedBindingBuilder visitConvertedConstant(
          ConvertedConstantBinding<? extends T> binding) {
View Full Code Here

  /**
   * Returns the {@code binder} accociated with {@code privateElements}. This can be used to
   * expose bindings to the enclosing environment.
   */
  protected PrivateBinder getPrivateBinder(PrivateElements privateElements) {
    PrivateBinder privateBinder = environmentToBinder.get(privateElements);
    checkArgument(privateBinder != null, "No private binder for %s", privateElements);
    return privateBinder;
  }
View Full Code Here

    final ImmutableSet<Key<?>> ab = ImmutableSet.of(a, b);

    checkModule(
        new AbstractModule() {
          protected void configure() {
            PrivateBinder one = binder().newPrivateBinder();
            one.expose(ArrayList.class);
            one.expose(Collection.class).annotatedWith(SampleAnnotation.class);
            one.bind(List.class).to(ArrayList.class);

            PrivateBinder two = binder().withSource("1 ElementsTest.java")
                .newPrivateBinder().withSource("2 ElementsTest.java");
            two.expose(String.class).annotatedWith(Names.named("a"));
            two.expose(b);
            two.bind(List.class).to(ArrayList.class);
          }
        },

        new FailingElementVisitor() {
          @Override public Void visit(PrivateElements one) {
            assertEquals(collections, one.getExposedKeys());
            checkElements(one.getElements(),
                new FailingElementVisitor() {
                  @Override public <T> Void visit(Binding<T> binding) {
                    assertEquals(Key.get(List.class), binding.getKey());
                    return null;
                  }
                }
            );
            return null;
          }
        },

        new FailingElementVisitor() {
          @Override public Void visit(PrivateElements two) {
            assertEquals(ab, two.getExposedKeys());
            assertEquals("1 ElementsTest.java", two.getSource());
            checkElements(two.getElements(),
                new FailingElementVisitor() {
                  @Override public <T> Void visit(Binding<T> binding) {
                    assertEquals("2 ElementsTest.java", binding.getSource());
                    assertEquals(Key.get(List.class), binding.getKey());
                    return null;
View Full Code Here

    {
        checkNotNull(name, "name is null");
        checkNotNull(serviceType, "serviceType is null");

        bindHttpBalancer(serviceType);
        PrivateBinder privateBinder = binder.newPrivateBinder();
        privateBinder.bind(HttpServiceBalancer.class).annotatedWith(ForBalancingHttpClient.class).to(Key.get(HttpServiceBalancer.class, serviceType));
        HttpClientBindingBuilder delegateBindingBuilder = httpClientPrivateBinder(privateBinder, binder).bindHttpClient(name, ForBalancingHttpClient.class);
        bindConfig(privateBinder).prefixedWith(name).to(BalancingHttpClientConfig.class);
        privateBinder.bind(HttpClient.class).annotatedWith(serviceType).to(BalancingHttpClient.class).in(Scopes.SINGLETON);
        privateBinder.expose(HttpClient.class).annotatedWith(serviceType);
        reportBinder(binder).export(HttpClient.class).annotatedWith(serviceType).withGeneratedName();

        return new BalancingHttpClientBindingBuilder(binder, serviceType, delegateBindingBuilder);
    }
View Full Code Here

    {
        checkNotNull(name, "name is null");
        checkNotNull(serviceType, "serviceType is null");
        checkNotNull(annotation, "annotation is null");

        PrivateBinder privateBinder = binder.newPrivateBinder();
        privateBinder.bind(HttpServiceBalancer.class).annotatedWith(ForBalancingHttpClient.class).to(Key.get(HttpServiceBalancer.class, serviceType));
        HttpClientBindingBuilder delegateBindingBuilder = httpClientPrivateBinder(privateBinder, binder).bindHttpClient(name, ForBalancingHttpClient.class);
        bindConfig(privateBinder).prefixedWith(name).to(BalancingHttpClientConfig.class);
        privateBinder.bind(HttpClient.class).annotatedWith(annotation).to(BalancingHttpClient.class).in(Scopes.SINGLETON);
        privateBinder.expose(HttpClient.class).annotatedWith(annotation);
        reportBinder(binder).export(HttpClient.class).annotatedWith(annotation).withGeneratedName();

        return new BalancingHttpClientBindingBuilder(binder, annotation, delegateBindingBuilder);
    }
View Full Code Here

    {
        checkNotNull(serviceType, "serviceType is null");
        checkNotNull(annotation, "annotation is null");

        bindHttpBalancer(serviceType);
        PrivateBinder privateBinder = binder.newPrivateBinder();
        privateBinder.bind(HttpServiceBalancer.class).annotatedWith(ForBalancingHttpClient.class).to(Key.get(HttpServiceBalancer.class, serviceType));
        HttpClientAsyncBindingBuilder delegateBindingBuilder = httpClientPrivateBinder(privateBinder, binder).bindAsyncHttpClient(serviceType.value(), ForBalancingHttpClient.class);
        bindConfig(privateBinder).prefixedWith(serviceType.value()).to(BalancingHttpClientConfig.class);
        privateBinder.bind(AsyncHttpClient.class).annotatedWith(annotation).to(BalancingAsyncHttpClient.class).in(Scopes.SINGLETON);
        privateBinder.expose(AsyncHttpClient.class).annotatedWith(annotation);
        reportBinder(binder).export(AsyncHttpClient.class).annotatedWith(annotation).withGeneratedName();

        return new BalancingHttpClientAsyncBindingBuilder(binder, annotation, delegateBindingBuilder);
    }
View Full Code Here

TOP

Related Classes of com.google.inject.PrivateBinder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.