Search in sources :

Example 6 with Binding

use of org.glassfish.jersey.internal.inject.Binding in project jersey by jersey.

the class Hk2Helper method bind.

/**
     * Bind descriptors to Hk2-like {@link Binder}.
     *
     * @param locator     HK2 locator.
     * @param descriptors collection of descriptors.
     */
static void bind(ServiceLocator locator, Iterable<Binding> descriptors) {
    DynamicConfiguration dc = getDynamicConfiguration(locator);
    for (Binding binding : descriptors) {
        bindBinding(locator, dc, binding);
    }
    dc.commit();
}
Also used : SupplierClassBinding(org.glassfish.jersey.internal.inject.SupplierClassBinding) AliasBinding(org.glassfish.jersey.internal.inject.AliasBinding) ClassBinding(org.glassfish.jersey.internal.inject.ClassBinding) InstanceBinding(org.glassfish.jersey.internal.inject.InstanceBinding) Binding(org.glassfish.jersey.internal.inject.Binding) SupplierInstanceBinding(org.glassfish.jersey.internal.inject.SupplierInstanceBinding) InjectionResolverBinding(org.glassfish.jersey.internal.inject.InjectionResolverBinding) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration)

Example 7 with Binding

use of org.glassfish.jersey.internal.inject.Binding in project jersey by jersey.

the class AbstractBinderTest method testFirstLayer.

@Test
public void testFirstLayer() {
    AbstractBinder binder = new AbstractBinder() {

        @Override
        protected void configure() {
            bind(CacheControlProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(CookieProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(DateProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(EntityTagProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(LinkProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
        }
    };
    List<Binding> bindings = new ArrayList<>(binder.getBindings());
    assertEquals(5, bindings.size());
    // Keep ordering.
    assertEquals(CacheControlProvider.class, ((ClassBinding) bindings.get(0)).getService());
    assertEquals(CookieProvider.class, ((ClassBinding) bindings.get(1)).getService());
    assertEquals(DateProvider.class, ((ClassBinding) bindings.get(2)).getService());
    assertEquals(EntityTagProvider.class, ((ClassBinding) bindings.get(3)).getService());
    assertEquals(LinkProvider.class, ((ClassBinding) bindings.get(4)).getService());
}
Also used : Binding(org.glassfish.jersey.internal.inject.Binding) ClassBinding(org.glassfish.jersey.internal.inject.ClassBinding) HeaderDelegateProvider(org.glassfish.jersey.spi.HeaderDelegateProvider) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with Binding

use of org.glassfish.jersey.internal.inject.Binding in project jersey by jersey.

the class CdiValidationResultBinder method done.

@Override
@SuppressWarnings("unchecked")
public void done() {
    if (beanManager != null) {
        // in CDI environment
        Binding binding = Bindings.supplier(new GenericCdiBeanSupplier(CdiValidationResult.class, injectionManager, beanManager, true)).to(CdiValidationResult.class).to(ValidationResult.class);
        injectionManager.register(binding);
    }
}
Also used : Binding(org.glassfish.jersey.internal.inject.Binding) GenericCdiBeanSupplier(org.glassfish.jersey.ext.cdi1x.internal.GenericCdiBeanSupplier)

Aggregations

Binding (org.glassfish.jersey.internal.inject.Binding)8 ClassBinding (org.glassfish.jersey.internal.inject.ClassBinding)4 ArrayList (java.util.ArrayList)2 GenericCdiBeanSupplier (org.glassfish.jersey.ext.cdi1x.internal.GenericCdiBeanSupplier)2 AbstractBinder (org.glassfish.jersey.internal.inject.AbstractBinder)2 InstanceBinding (org.glassfish.jersey.internal.inject.InstanceBinding)2 HeaderDelegateProvider (org.glassfish.jersey.spi.HeaderDelegateProvider)2 Test (org.junit.Test)2 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)1 AliasBinding (org.glassfish.jersey.internal.inject.AliasBinding)1 InjectionResolverBinding (org.glassfish.jersey.internal.inject.InjectionResolverBinding)1 SupplierClassBinding (org.glassfish.jersey.internal.inject.SupplierClassBinding)1 SupplierInstanceBinding (org.glassfish.jersey.internal.inject.SupplierInstanceBinding)1 Component (org.springframework.stereotype.Component)1