@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; }
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); }
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); } } }
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); }
/** * 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); }
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))); } }
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); }
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); }
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; }
/** * 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); }
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"); }
void configure(PrivateBinder binder) { binder = binder.withSource(source); if (errors.hasErrors()) { for (Message message : errors.getMessages()) { binder.addError(message); } } else { bindProvidersInScope(binder); } }
private void bindProvidersInScope(PrivateBinder privateBinder) { ScopedBindingBuilder scoper = privateBinder.bind(providersClass); if (scopeAnnotation != null) { scoper.in(scopeAnnotation); } for (EventualProvider<?> p : providers) { p.bindFutureProvider(privateBinder); } }
@Override public void configure(Binder binder) { PrivateBinder privateBinder = binder.newPrivateBinder(); for (Providers<?> partial : partials) { partial.configure(privateBinder); } }
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)); }
@Override public PrivateBinder newPrivateBinder() { PrivateElementsImpl privateElements = new PrivateElementsImpl(getElementSource()); RecordingBinder binder = new RecordingBinder(this, privateElements); privateBinders.add(binder); elements.add(privateElements); return binder; }
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); } }
@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()); } }
public PrivateBinder newPrivateBinder() { PrivateElementsImpl privateElements = new PrivateElementsImpl(getElementSource()); RecordingBinder binder = new RecordingBinder(this, privateElements); elements.add(privateElements); rehashables.add(binder); return binder; }
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()); } }
public static void expose(PrivateBinder binder, Iterable<? extends Module> modules) { visit(new ElementExposer(binder), modules); }
public static void expose(PrivateBinder binder, Module... modules) { visit(new ElementExposer(binder), modules); }
public ElementExposer(PrivateBinder binder) { this.binder = binder; }
@Override default PrivateBinder withSource(final Object source) { return this.binder().withSource(source); }
@Override default PrivateBinder skipSources(final Class... classesToSkip) { return this.binder().skipSources(classesToSkip); }
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); }
@NonNull @Override public PrivateBinder binder() { return this.privateBinder; }
@Override default PrivateBinder newPrivateBinder() { return this.binder().newPrivateBinder(); }
VPrivateBinderImpl(@NonNull final PrivateBinder binder) { this.binder = binder.skipSources(SKIPPED_SOURCES); }
@NonNull @Override public PrivateBinder binder() { return this.binder; }
private <T> void exposeOption(Class<T> type) { ((PrivateBinder) binder()).expose(type).annotatedWith(Option.class); }
PrivateBinderAdapter(PrivateBinder privateBinder, GinjectorBindings bindings) { super(privateBinder, bindings); this.privateBinder = privateBinder; }
@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); }
public PrivateBinder newPrivateBinder() { PrivateElementsImpl privateElements = new PrivateElementsImpl(getSource()); elements.add(privateElements); return new RecordingBinder(this, privateElements); }
/** * Gets the forwarded private binder that methods are forwarded to. * * @return the forwarded private binder */ @NonNull @Override PrivateBinder binder();
/** * 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);