use of com.google.inject.PrivateBinder in project roboguice by roboguice.
the class PrivateElementsImpl method applyTo.
public void applyTo(Binder binder) {
PrivateBinder privateBinder = binder.withSource(source).newPrivateBinder();
for (Element element : getElements()) {
element.applyTo(privateBinder);
}
// ensure exposedKeysToSources is populated
getExposedKeys();
for (Map.Entry<Key<?>, Object> entry : exposedKeysToSources.entrySet()) {
privateBinder.withSource(entry.getValue()).expose(entry.getKey());
}
}
use of com.google.inject.PrivateBinder in project guice by google.
the class CheckedProviderMethod method configure.
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);
}
use of com.google.inject.PrivateBinder in project guice by google.
the class PrivateElementsImpl method applyTo.
@Override
public void applyTo(Binder binder) {
PrivateBinder privateBinder = binder.withSource(source).newPrivateBinder();
for (Element element : getElements()) {
element.applyTo(privateBinder);
}
// ensure exposedKeysToSources is populated
getExposedKeys();
for (Map.Entry<Key<?>, Object> entry : exposedKeysToSources.entrySet()) {
privateBinder.withSource(entry.getValue()).expose(entry.getKey());
}
}
use of com.google.inject.PrivateBinder in project OpenAM by OpenRock.
the class DataLayerConnectionModule method configure.
@Override
protected void configure() {
PrivateBinder binder = binder().withSource(connectionType);
binder.bind(ConnectionType.class).toInstance(connectionType);
configureConnections(binder);
configureTaskExecutor(binder);
configureDataStore(binder);
expose(binder, ConnectionFactory.class);
expose(binder, QueryFactory.class);
if (exposesQueueConfiguration) {
expose(binder, QueueConfiguration.class);
}
if (executorType != null) {
expose(binder, TaskFactory.class);
expose(binder, TaskExecutor.class);
}
}
use of com.google.inject.PrivateBinder in project guice by google.
the class ElementsTest method testNewPrivateBinder.
public void testNewPrivateBinder() {
final Key<Collection> collection = Key.get(Collection.class, SampleAnnotation.class);
final Key<ArrayList> arrayList = Key.get(ArrayList.class);
final ImmutableSet<Key<?>> collections = ImmutableSet.<Key<?>>of(arrayList, collection);
final Key<?> a = Key.get(String.class, Names.named("a"));
final Key<?> b = Key.get(String.class, Names.named("b"));
final ImmutableSet<Key<?>> ab = ImmutableSet.of(a, b);
checkModule(new AbstractModule() {
@Override
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 FooBar").newPrivateBinder().withSource("2 FooBar");
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 ExternalFailureVisitor() {
@Override
public Void visit(PrivateElements two) {
assertEquals(ab, two.getExposedKeys());
assertEquals("1 FooBar", two.getSource().toString());
checkElements(two.getElements(), new ExternalFailureVisitor() {
@Override
public <T> Void visit(Binding<T> binding) {
assertEquals("2 FooBar", binding.getSource().toString());
assertEquals(Key.get(List.class), binding.getKey());
return null;
}
});
return null;
}
});
}
Aggregations