Package org.glassfish.hk2.api

Examples of org.glassfish.hk2.api.ServiceLocator


     * job of the factory to keep track of the items it produces, that
     * will be done by the scoped context
     */
    @TenantScoped
    public Environment provide() {
        ServiceLocator locator = getCurrentLocator();
       
        return locator.getService(Environment.class);
    }
View Full Code Here


    }
   
    private ServiceLocator getCurrentLocator() {
        if (manager.getCurrentTenant() == null) throw new IllegalStateException("There is no current tenant");
       
        ServiceLocator locator = backingLocators.get(manager.getCurrentTenant());
        if (locator == null) {
            locator = createNewLocator();
            backingLocators.put(manager.getCurrentTenant(), locator);
        }
       
View Full Code Here

    public final static int BOB_MAX = 20;
   
    public ServiceLocator generateLocatorPerTenant(String tenantName) {
        if (tenantName == null) throw new IllegalArgumentException();
       
        ServiceLocator serviceLocator =
            systemModulesRegistry.createServiceLocator(systemServiceLocator, "tenant-scoped", null);

        populateWithConfig(serviceLocator, tenantName);
       
        return serviceLocator;
View Full Code Here

        this.deployment = deployment;
    }

    public <T> void aroundInject(InjectionContext<T> injectionContext) {
        try {
            ServiceLocator serviceLocator = Globals.getDefaultHabitat();
            ComponentEnvManager compEnvManager = serviceLocator.getService(ComponentEnvManager.class);
            EjbContainerServices containerServices = serviceLocator.getService(EjbContainerServices.class);

            JndiNameEnvironment componentEnv = compEnvManager.getCurrentJndiNameEnvironment();

            ManagedBeanDescriptor mbDesc = null;
View Full Code Here

    public static boolean isImplicitBeanDiscoveryEnabled() {
        boolean result = false;

        // Check the "global" configuration
        ServiceLocator serviceLocator = Globals.getDefaultHabitat();
        if (serviceLocator != null) {
            Config config = serviceLocator.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
            if (config != null) {
                result = Boolean.valueOf(config.getExtensionByType(CDIService.class).getEnableImplicitCdi());
            }
        }
View Full Code Here

            final Parameter parameter = parameterCache.compute(injectionPoint);

            if (parameter != null) {

                final ServiceLocator locator = beanManager.getExtension(CdiComponentProvider.class).locator;

                final Set<ValueFactoryProvider> providers = Providers.getProviders(locator, ValueFactoryProvider.class);

                for (final ValueFactoryProvider vfp : providers) {
                    final Factory<?> valueFactory = vfp.getValueFactory(parameter);
View Full Code Here

    /**
     * Test that defined ServiceLocator becomes a parent of the newly created service locator.
     */
    @Test
    public void testParentServiceLocator() {
        final ServiceLocator locator = new ServiceLocatorImpl("MyServiceLocator", null);
        final Server server = JettyHttpContainerFactory.createServer(URI.create("http://localhost:9876"),
                    new ResourceConfig(Resource.class), false, locator);
            JettyHttpContainer container = (JettyHttpContainer) server.getHandler();
            ServiceLocator appLocator = container.getApplicationHandler().getServiceLocator();
            assertTrue("Application service locator was expected to have defined parent locator", appLocator.getParent() == locator);
    }
View Full Code Here

        RuntimeDelegate.setInstance(new TestRuntimeDelegate());
    }

    @Test
    public void testProviders() throws Exception {
        final ServiceLocator locator = Injections.createLocator(new ContextInjectionResolver.Binder(), new TestBinder(),
                new MessagingBinders.MessageBodyProviders(null, RuntimeType.SERVER), new Binder());

        TestBinder.initProviders(locator);
        RequestScope scope = locator.getService(RequestScope.class);

        scope.runInScope(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                Providers instance = locator.getService(Providers.class);

                assertNotNull(instance);
                assertSame(JaxrsProviders.class, instance.getClass());

                assertNotNull(instance.getExceptionMapper(Throwable.class));
View Full Code Here

        RuntimeDelegate.setInstance(new TestRuntimeDelegate());
    }

    @Before
    public void setUp() {
        final ServiceLocator locator = Injections.createLocator(new ContextResolverFactory.Binder(), new Binder());
        final ProviderBinder providerBinder = new ProviderBinder(locator);
        providerBinder.bindClasses(Sets.<Class<?>>newHashSet(CustomIntegerResolverC.class));

        crf = locator.getService(ContextResolverFactory.class);
    }
View Full Code Here

    private static class ServiceLocatorShutdownListener extends AbstractContainerLifecycleListener {

        @Override
        public void onShutdown(final Container container) {
            final ApplicationHandler handler = container.getApplicationHandler();
            final ServiceLocator locator = handler.getServiceLocator();

            // Call @PreDestroy method on Application.
            locator.preDestroy(getWrappedApplication(handler.getConfiguration()));
            // Shutdown ServiceLocator.
            Injections.shutdownLocator(locator);
        }
View Full Code Here

TOP

Related Classes of org.glassfish.hk2.api.ServiceLocator

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.