Java 类com.google.inject.PrivateBinder 实例源码

项目:ProjectAres    文件:Scoper.java   
@Override
public Void visit(ExposedBinding<? extends T> binding) {
    final PrivateBinder privateBinder = this.binder.newPrivateBinder();
    final Scoper scoper = new Scoper(privateBinder, scoping);
    for(Element element : binding.getPrivateElements().getElements()) {
        if(element instanceof Binding) {
            ((Binding) element).acceptTargetVisitor(scoper);
        } else {
            element.applyTo(privateBinder);
        }
    }
    for(Key key : binding.getPrivateElements().getExposedKeys()) {
        privateBinder.expose(key);
    }
    return null;
}
项目:walkaround    文件:StoreModuleHelper.java   
public static void makeBasicBindingsAndExposures(PrivateBinder binder,
    Class<? extends Annotation> annotation) {
  binder.bind(SlobFacilities.class).to(FacilitiesImpl.class);
  binder.bind(SlobStore.class).to(SlobStoreImpl.class);
  binder.install(factoryModule(MutationLogFactory.class, MutationLog.class));

  binder.bind(MutationLogFactory.class).annotatedWith(annotation).to(MutationLogFactory.class);
  binder.bind(SlobStore.class).annotatedWith(annotation).to(SlobStore.class);
  binder.bind(LocalMutationProcessor.class).annotatedWith(annotation)
      .to(LocalMutationProcessor.class);
  binder.bind(SlobFacilities.class).annotatedWith(annotation).to(FacilitiesImpl.class);

  binder.expose(MutationLogFactory.class).annotatedWith(annotation);
  binder.expose(SlobStore.class).annotatedWith(annotation);
  binder.expose(LocalMutationProcessor.class).annotatedWith(annotation);
  binder.expose(SlobFacilities.class).annotatedWith(annotation);

  // Make sure a binding for the Set exists.
  Multibinder.newSetBinder(binder, PreCommitAction.class);
  // Make sure a binding for the Set exists.
  Multibinder.newSetBinder(binder, PostCommitAction.class);
}
项目:miscellaneous    文件:Providers.java   
void bindFutureProvider(PrivateBinder binder) {
  binder = binder.withSource(source);

  ScopedBindingBuilder scoper = binder.bind(bindingKey).toProvider(this);

  if (isVoid(method)) {
    scoper.asEagerSingleton();
  } else {
    if (scopeAnnotation != null) {
      scoper.in(scopeAnnotation);
    }
    if (exposedBinding) {
      binder.expose(bindingKey);
    }
  }
}
项目:LanternServer    文件:OptionModule.java   
protected void exposeOptions() {
    final Binder binder = binder();
    if (!(binder instanceof PrivateBinder)) {
        return;
    }
    exposeOption(Integer.class);
    exposeOption(Long.class);
    exposeOption(Double.class);
    exposeOption(Short.class);
    exposeOption(String.class);
    exposeOption(Boolean.class);
    exposeOption(Byte.class);
    exposeOption(Float.class);
    exposeOption(Integer.class);
    exposeOption(File.class);
    exposeOption(Path.class);
}
项目:r01fb    文件:ServicesClientAPIBootstrapGuiceModuleBase.java   
/**
 * Binds the {@link ServiceProxiesAggregator} that MUST contain fields of types implementing {@link ServiceInterface} which are 
 * the concrete proxy implementation to the services
 * 
 * The {@link ServiceInterface} fields of {@link ServiceProxiesAggregator} implementing type are LAZY loaded by 
 * {@link ServicesClientProxyLazyLoaderGuiceMethodInterceptor} which guesses what proxy implementation assign to the field:
 * <ul>
 *      <li>If the {@link ServiceProxiesAggregator} extends {@link ServiceProxiesAggregatorForDefaultImpls}, the concrete {@link ServiceInterface}-implementing 
 *          proxy instance is taken from the client properties XML file, so some service impls might be accessed using a BEAN proxy while others might be accessed
 *          using a REST proxy -depending on the properties file-</li>
 *      <li>If the {@link ServiceInterface} field's BEAN implementation is available this one will be assigned to the field no matter what type the aggregator is</li>
 * </ul>
 * @param binder
 */
private void _bindServiceProxiesAggregators(final Binder binder) {
    // Inject all Map fields that matches the service interface types with the bean impl or proxy to be used
    // (this Map fields are injected by MapBinders created at ServicesForAppModulePrivateGuiceModule)                                   
    binder.requestInjection(_serviceInterfaceTypesToImplOrProxyMappings);

    // Create a private binder to be used to inject the MethodInterceptor that will intercept all fine-grained
    // proxy accessor method calls at ServicesAggregatorClientProxy 
    // The interceptor lazily loads the fine-grained proxy instances and makes the aggregator creation simpler
    PrivateBinder privateBinder = binder.newPrivateBinder();
    privateBinder.bind(ServiceInterfaceTypesToImplOrProxyMappings.class)
                 .toInstance(_serviceInterfaceTypesToImplOrProxyMappings);
    MethodInterceptor serviceProxyGetterInterceptor = new ServicesClientProxyLazyLoaderGuiceMethodInterceptor(_apiAppAndModule,
                                                                                                              _coreAppAndModules);
    privateBinder.requestInjection(serviceProxyGetterInterceptor);      // the method interceptor is feeded with a map of service interfaces to bean impl or proxy created below

    // Bind the interceptor to ServiceProxiesAggregator type's fine-grained method calls
    binder.bindInterceptor(Matchers.subclassesOf(ServiceProxiesAggregator.class),
                           Matchers.any(),
                           serviceProxyGetterInterceptor);

    // Bind every services proxy aggregator implementation
    log.info("[ServiceProxyAggregator] > {}",_servicesProxiesAggregatorType);
    binder.bind(_servicesProxiesAggregatorType)
          .in(Singleton.class);
}
项目:r01fb    文件:ServicesCoreBootstrapGuiceModuleBase.java   
private static void _doBindXMLPropertiesComponentProviderAs(final CoreAppCode coreAppCode,final CoreModule coreAppComponent,
                                                            final String bindingName,final String subComponent,
                                                            final Binder binder,final boolean expose) {
    log.debug("{}.{}.properties.xml properties are available for injection as a {} object annotated with @XMLPropertiesComponent(\"{}\") INTERNALLY and @XMLPropertiesComponent(\"{}\") EXTERNALLY",
              coreAppCode,_componentPropertiesIdFor(coreAppComponent,subComponent),
              XMLPropertiesForAppComponent.class.getSimpleName(),
              subComponent,
              _componentPropertiesIdFor(coreAppComponent,subComponent));

    // do the binding
    binder.bind(XMLPropertiesForAppComponent.class)
          .annotatedWith(new XMLPropertiesComponentImpl(bindingName))
          .toProvider(new XMLPropertiesForXProvider(coreAppCode,coreAppComponent,subComponent))
          .in(Singleton.class);

    // Expose xml properties binding
    if (expose && (binder instanceof PrivateBinder)) {
        log.warn("{}.{}.properties.xml properties are available for injection as a {} object annotated with @XMLPropertiesComponent(\"{}\")",
                 coreAppCode,_componentPropertiesIdFor(coreAppComponent,subComponent),
                 XMLPropertiesForAppComponent.class.getSimpleName(),
                 _componentPropertiesIdFor(coreAppComponent,subComponent));
        PrivateBinder pb = (PrivateBinder)binder;
        pb.expose(Key.get(XMLPropertiesForAppComponent.class,new XMLPropertiesComponentImpl(bindingName)));
    }
}
项目:guice    文件:CheckedProviderMethod.java   
void configure(Binder binder) {
  binder = binder.withSource(method);

  SecondaryBinder<?, ?> sbinder =
      ThrowingProviderBinder.create(binder).bind(checkedProvider, key.getTypeLiteral());
  if (key.getAnnotation() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotation());
  } else if (key.getAnnotationType() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotationType());
  }
  sbinder.scopeExceptions(scopeExceptions);
  ScopedBindingBuilder sbbuilder = sbinder.toProviderMethod(this);
  if (scopeAnnotation != null) {
    sbbuilder.in(scopeAnnotation);
  }

  if (exposed) {
    // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
    // misplaced @Exposed, calling this will add an error to the binder's error queue
    ((PrivateBinder) binder).expose(sbinder.getKey());
  }

  CheckedProvideUtils.validateExceptions(
      binder, exceptionTypes, sbinder.getExceptionTypes(), checkedProvider);
}
项目:guice-old    文件:CheckedProviderMethod.java   
void configure(Binder binder) {
  binder = binder.withSource(method);

  SecondaryBinder<?, ?> sbinder = 
    ThrowingProviderBinder.create(binder)
      .bind(checkedProvider, key.getTypeLiteral());
  if(key.getAnnotation() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotation());
  } else if(key.getAnnotationType() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotationType());
  } 
  ScopedBindingBuilder sbbuilder = sbinder.toProviderMethod(this);
  if(scopeAnnotation != null) {
    sbbuilder.in(scopeAnnotation);
  }

  if (exposed) {
    // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
    // misplaced @Exposed, calling this will add an error to the binder's error queue
    ((PrivateBinder) binder).expose(sbinder.getKey());
  }

  CheckedProvideUtils.validateExceptions(
      binder, exceptionTypes, sbinder.getExceptionTypes(), checkedProvider);
}
项目:google-guice    文件:CheckedProviderMethod.java   
void configure(Binder binder) {
  binder = binder.withSource(method);

  SecondaryBinder<?, ?> sbinder = 
    ThrowingProviderBinder.create(binder)
      .bind(checkedProvider, key.getTypeLiteral());
  if(key.getAnnotation() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotation());
  } else if(key.getAnnotationType() != null) {
    sbinder = sbinder.annotatedWith(key.getAnnotationType());
  } 
  ScopedBindingBuilder sbbuilder = sbinder.toProviderMethod(this);
  if(scopeAnnotation != null) {
    sbbuilder.in(scopeAnnotation);
  }

  if (exposed) {
    // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
    // misplaced @Exposed, calling this will add an error to the binder's error queue
    ((PrivateBinder) binder).expose(sbinder.getKey());
  }

  CheckedProvideUtils.validateExceptions(
      binder, exceptionTypes, sbinder.getExceptionTypes(), checkedProvider);
}
项目:ProjectAres    文件:PrivateBinders.java   
static PrivateBinders wrap(PrivateBinder binder) {
    if(binder instanceof PrivateBinders) {
        return (PrivateBinders) binder;
    }
    final PrivateBinder skipped = binder.skipSources(Binders.class,
                                                     PrivateBinders.class,
                                                     ForwardingBinder.class,
                                                     ForwardingPrivateBinder.class);
    return () -> skipped;
}
项目:violet    文件:VPrivateBinder.java   
/**
 * Creates a wrapped private binder.
 *
 * @param binder the private binder
 * @return a wrapped private binder
 */
@NonNull
static VPrivateBinder of(@NonNull final PrivateBinder binder) {
  // avoid re-wrapping
  if(binder instanceof VPrivateBinder) {
    return (VPrivateBinder) binder;
  }
  return new VPrivateBinderImpl(binder);
}
项目:walkaround    文件:StoreModuleHelper.java   
public static void bindEntityKinds(PrivateBinder binder, String prefix) {
  binder.bind(String.class).annotatedWith(SlobRootEntityKind.class).toInstance(prefix);
  binder.bind(String.class).annotatedWith(SlobDeltaEntityKind.class)
      .toInstance(prefix + "Delta");
  binder.bind(String.class).annotatedWith(SlobSnapshotEntityKind.class)
      .toInstance(prefix + "Snapshot");
  binder.bind(String.class).annotatedWith(SlobSynchronizationEntityKind.class)
      .toInstance(prefix + "Sync");
}
项目:miscellaneous    文件:Providers.java   
void configure(PrivateBinder binder) {
  binder = binder.withSource(source);

  if (errors.hasErrors()) {
    for (Message message : errors.getMessages()) {
      binder.addError(message);
    }
  } else {
    bindProvidersInScope(binder);
  }
}
项目:miscellaneous    文件:Providers.java   
private void bindProvidersInScope(PrivateBinder privateBinder) {
  ScopedBindingBuilder scoper = privateBinder.bind(providersClass);

  if (scopeAnnotation != null) {
    scoper.in(scopeAnnotation);
  }

  for (EventualProvider<?> p : providers) {
    p.bindFutureProvider(privateBinder);
  }
}
项目:miscellaneous    文件:EventualModules.java   
@Override
public void configure(Binder binder) {
  PrivateBinder privateBinder = binder.newPrivateBinder();
  for (Providers<?> partial : partials) {
    partial.configure(privateBinder);
  }
}
项目:google-gin    文件:PrivateGinModuleAdapter.java   
public void configure() {
  Binder binder = binder().skipSources(PrivateGinModuleAdapter.class,
      BinderAdapter.class, PrivateBinderAdapter.class, PrivateGinModule.class);

  ginModule.configure(new PrivateBinderAdapter((PrivateBinder) binder,
      bindings == null ? null : bindings.createChildGinjectorBindings(ginModule.getClass())));

  // Install provider methods from the GinModule
  binder.install(ProviderMethodsModule.forObject(ginModule));
}
项目:guice    文件:Elements.java   
@Override
public PrivateBinder newPrivateBinder() {
  PrivateElementsImpl privateElements = new PrivateElementsImpl(getElementSource());
  RecordingBinder binder = new RecordingBinder(this, privateElements);
  privateBinders.add(binder);
  elements.add(privateElements);
  return binder;
}
项目:guice    文件:ProviderMethod.java   
public void configure(Binder binder) {
  binder = binder.withSource(method);

  if (scopeAnnotation != null) {
    binder.bind(key).toProvider(this).in(scopeAnnotation);
  } else {
    binder.bind(key).toProvider(this);
  }

  if (exposed) {
    // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
    // misplaced @Exposed, calling this will add an error to the binder's error queue
    ((PrivateBinder) binder).expose(key);
  }
}
项目:guice    文件:PrivateElementsImpl.java   
@Override
public void applyTo(Binder binder) {
  PrivateBinder privateBinder = binder.withSource(source).newPrivateBinder();

  for (Element element : getElements()) {
    element.applyTo(privateBinder);
  }

  getExposedKeys(); // ensure exposedKeysToSources is populated
  for (Map.Entry<Key<?>, Object> entry : exposedKeysToSources.entrySet()) {
    privateBinder.withSource(entry.getValue()).expose(entry.getKey());
  }
}
项目:guice-old    文件:Elements.java   
public PrivateBinder newPrivateBinder() {
  PrivateElementsImpl privateElements = new PrivateElementsImpl(getElementSource());
  RecordingBinder binder = new RecordingBinder(this, privateElements);
  elements.add(privateElements);
  rehashables.add(binder);
  return binder;
}
项目:guice-old    文件:ProviderMethod.java   
public void configure(Binder binder) {
  binder = binder.withSource(method);

  if (scopeAnnotation != null) {
    binder.bind(key).toProvider(this).in(scopeAnnotation);
  } else {
    binder.bind(key).toProvider(this);
  }

  if (exposed) {
    // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
    // misplaced @Exposed, calling this will add an error to the binder's error queue
    ((PrivateBinder) binder).expose(key);
  }
}
项目:guice-old    文件:PrivateElementsImpl.java   
public void applyTo(Binder binder) {
  PrivateBinder privateBinder = binder.withSource(source).newPrivateBinder();

  for (Element element : getElements()) {
    element.applyTo(privateBinder);
  }

  getExposedKeys(); // ensure exposedKeysToSources is populated
  for (Map.Entry<Key<?>, Object> entry : exposedKeysToSources.entrySet()) {
    privateBinder.withSource(entry.getValue()).expose(entry.getKey());
  }
}
项目:google-guice    文件:ProviderMethod.java   
public void configure(Binder binder) {
  binder = binder.withSource(method);

  if (scopeAnnotation != null) {
    binder.bind(key).toProvider(this).in(scopeAnnotation);
  } else {
    binder.bind(key).toProvider(this);
  }

  if (exposed) {
    // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
    // misplaced @Exposed, calling this will add an error to the binder's error queue
    ((PrivateBinder) binder).expose(key);
  }
}
项目:google-guice    文件:PrivateElementsImpl.java   
public void applyTo(Binder binder) {
  PrivateBinder privateBinder = binder.withSource(source).newPrivateBinder();

  for (Element element : getElements()) {
    element.applyTo(privateBinder);
  }

  getExposedKeys(); // ensure exposedKeysToSources is populated
  for (Map.Entry<Key<?>, Object> entry : exposedKeysToSources.entrySet()) {
    privateBinder.withSource(entry.getValue()).expose(entry.getKey());
  }
}
项目:ProjectAres    文件:ElementUtils.java   
public static void expose(PrivateBinder binder, Iterable<? extends Module> modules) {
    visit(new ElementExposer(binder), modules);
}
项目:ProjectAres    文件:ElementUtils.java   
public static void expose(PrivateBinder binder, Module... modules) {
    visit(new ElementExposer(binder), modules);
}
项目:ProjectAres    文件:ElementExposer.java   
public ElementExposer(PrivateBinder binder) {
    this.binder = binder;
}
项目:violet    文件:ForwardingPrivateBinder.java   
@Override
default PrivateBinder withSource(final Object source) {
  return this.binder().withSource(source);
}
项目:violet    文件:ForwardingPrivateBinder.java   
@Override
default PrivateBinder skipSources(final Class... classesToSkip) {
  return this.binder().skipSources(classesToSkip);
}
项目:violet    文件:DuplexBinder.java   
DuplexBinderImpl(final Binder publicBinder, final PrivateBinder privateBinder) {
  this.publicBinder = publicBinder.skipSources(SKIPPED_SOURCES);
  // Special case DuplexBinder to prevent creation of a new DuplexBinderImpl when skipping sources
  this.privateBinder = (privateBinder instanceof DuplexBinder ? ((DuplexBinder) privateBinder).binder() : privateBinder).skipSources(SKIPPED_SOURCES);
}
项目:violet    文件:DuplexBinder.java   
@NonNull
@Override
public PrivateBinder binder() {
  return this.privateBinder;
}
项目:violet    文件:ForwardingBinder.java   
@Override
default PrivateBinder newPrivateBinder() {
  return this.binder().newPrivateBinder();
}
项目:violet    文件:VPrivateBinder.java   
VPrivateBinderImpl(@NonNull final PrivateBinder binder) {
  this.binder = binder.skipSources(SKIPPED_SOURCES);
}
项目:violet    文件:VPrivateBinder.java   
@NonNull
@Override
public PrivateBinder binder() {
  return this.binder;
}
项目:LanternServer    文件:OptionModule.java   
private <T> void exposeOption(Class<T> type) {
    ((PrivateBinder) binder()).expose(type).annotatedWith(Option.class);
}
项目:google-gin    文件:PrivateBinderAdapter.java   
PrivateBinderAdapter(PrivateBinder privateBinder, GinjectorBindings bindings) {
  super(privateBinder, bindings);
  this.privateBinder = privateBinder;
}
项目:r01fb    文件:DBGuiceModuleBase.java   
@Override
public void configure(final Binder binder) {
    Binder theBinder = binder;

    // [0] - JPA
    // The JPA persistence unit name is composed by:
    //      - The appCode/component
    //      - The PersistenceUnitType: driverManager (connection) / dataSource
    // So the persistence unit name to use at the persistence.xml file is composed like:
    //      <persistence-unit name="persistenceUnit.{appCode}.{appComponent}.{persistenceUnitType}">
    PersistenceUnitType persistenceUnitType = this.propertyAt("persistence/@unitType")
                                                  .asEnumElement(PersistenceUnitType.class,
                                                                 PersistenceUnitType.DRIVER_MANAGER);   // use driverManager by default

    // Sometimes it's an app component (ie: the urlAlias component for the r01t app)
    // On these cases:
    //  - the persistence properties are going to be looked after as  {appCode}.{appComponent}.persistence.properties.xml
    //  - the persistence unit is going to be looked after as persistenceUnit.{appCode}.{appComponent}
    //    otherwise (no appComponent is set):
    //  - the persistence properties are going to be looked after as  {appCode}.persistence.properties.xml
    //  - the persistence unit is going to be looked after as persistenceUnit.{appCode} 
    String jpaServiceName = this.getAppComponent() == null ? this.getAppCode().asString()
                                                           : Strings.customized("{}.{}",
                                                                                this.getAppCode(),this.getAppComponent());
    final String persistenceUnitName = _persistenceUnitName(persistenceUnitType);

    // Load properties
    Properties props = _persistenceUnitProperties(persistenceUnitType,
                                                  persistenceUnitName);

    // Create the module    
    JpaPersistModule jpaModule = new JpaPersistModule(persistenceUnitName); // for an alternative way see http://stackoverflow.com/questions/18101488/does-guice-persist-provide-transaction-scoped-or-application-managed-entitymanag
    jpaModule.properties(props);
    theBinder.install(jpaModule);


    // Service handler used to control (start/stop) the Persistence Service (see ServletContextListenerBase)
    theBinder.bind(ServiceHandler.class)                    
             .annotatedWith(Names.named(jpaServiceName))
             .to(JPAPersistenceServiceControl.class)
             .in(Singleton.class);  //.asEagerSingleton();

    // expose the JPA's service handler 
    if (theBinder instanceof PrivateBinder) {
        PrivateBinder privateBinder = (PrivateBinder)binder;
        privateBinder.expose(ServiceHandler.class)
                     .annotatedWith(Names.named(jpaServiceName));
    }


    log.warn("... binded jpa persistence unit {} whose entity manager is handled by ServiceHandler with name {}",persistenceUnitName,jpaServiceName);
}
项目:google-guice    文件:Elements.java   
public PrivateBinder newPrivateBinder() {
  PrivateElementsImpl privateElements = new PrivateElementsImpl(getSource());
  elements.add(privateElements);
  return new RecordingBinder(this, privateElements);
}
项目:violet    文件:ForwardingPrivateBinder.java   
/**
 * Gets the forwarded private binder that methods are forwarded to.
 *
 * @return the forwarded private binder
 */
@NonNull
@Override
PrivateBinder binder();
项目:r01fb    文件:ServicesCoreBootstrapGuiceModuleExposesBindings.java   
/**
 * Provides the {@link ServicesCoreBootstrapGuiceModule} with the {@link PrivateBinder} to give him
 * the oportunity to expose something to the outside world
 * @param privateBinder
 */
public void exposeBindings(final PrivateBinder privateBinder);