Search in sources :

Example 71 with Named

use of javax.inject.Named in project Payara by payara.

the class AppServerStartupTest method bindService.

private void bindService(DynamicConfiguration configurator, Class<?> service) {
    final DescriptorBuilder descriptorBuilder = BuilderHelper.link(service);
    final RunLevel rla = service.getAnnotation(RunLevel.class);
    if (rla != null) {
        descriptorBuilder.to(RunLevel.class).has(RunLevel.RUNLEVEL_VAL_META_TAG, Collections.singletonList(((Integer) rla.value()).toString())).has(RunLevel.RUNLEVEL_MODE_META_TAG, Collections.singletonList(((Integer) rla.mode()).toString()));
        descriptorBuilder.in(RunLevel.class);
    }
    Class clazz = service;
    while (clazz != null) {
        Class<?>[] interfaces = clazz.getInterfaces();
        for (int j = 0; j < interfaces.length; j++) {
            descriptorBuilder.to(interfaces[j]);
        }
        clazz = clazz.getSuperclass();
    }
    final Named named = service.getAnnotation(Named.class);
    if (named != null) {
        descriptorBuilder.named(named.value());
    }
    configurator.bind(descriptorBuilder.build());
}
Also used : Named(javax.inject.Named) PostStartupRunLevel(org.glassfish.internal.api.PostStartupRunLevel) RunLevel(org.glassfish.hk2.runlevel.RunLevel) InitRunLevel(org.glassfish.internal.api.InitRunLevel) StartupRunLevel(org.glassfish.api.StartupRunLevel) DescriptorBuilder(org.glassfish.hk2.utilities.DescriptorBuilder)

Example 72 with Named

use of javax.inject.Named in project Payara by payara.

the class HK2DomConfigTypesUtilities method enableHK2DomConfigurationConfigTypes.

/**
 * This method enables the HK2 Dom based XML configuration parsing for
 * systems that do not use HK2 metadata files or use a non-default
 * name for HK2 metadata files, along with support for the types
 * provided in this module.  This method is idempotent, so that
 * if the services already are available in the locator they will
 * not get added again
 *
 * @param locator The non-null locator to add the hk2 dom based
 * configuration services to
 * @param loader The loader to use to classload the services added
 */
public static void enableHK2DomConfigurationConfigTypes(ServiceLocator locator, HK2Loader loader) {
    if (locator.getBestDescriptor(BuilderHelper.createContractFilter(PROPERTY_GENERATED_INJECTOR_CLASS)) != null)
        return;
    HK2DomConfigUtilities.enableHK2DomConfiguration(locator, loader);
    LinkedList<String> namedList = new LinkedList<String>();
    namedList.add(REQUIRED);
    namedList.add(STRING_DATATYPE);
    namedList.add(LEAF);
    LinkedList<String> valueList = new LinkedList<String>();
    valueList.add(REQUIRED);
    valueList.add(STRING_DATATYPE);
    valueList.add(LEAF);
    LinkedList<String> keyedAsList = new LinkedList<String>();
    keyedAsList.add(PROPERTY_CLASS);
    LinkedList<String> targetList = new LinkedList<String>();
    targetList.add(PROPERTY_CLASS);
    LinkedList<String> descriptionList = new LinkedList<String>();
    descriptionList.add(OPTIONAL);
    descriptionList.add(STRING_DATATYPE);
    descriptionList.add(LEAF);
    DescriptorImpl injectorDescriptor = BuilderHelper.link(PROPERTY_GENERATED_INJECTOR_CLASS).to(CONFIG_INJECTOR_CLASS).in(Singleton.class.getName()).named(NAME).qualifiedBy(INJECTION_TARGET_QUALIFIER).has(NAME_FIELD, namedList).has(VALUE_FIELD, valueList).has(KEYED_AS, keyedAsList).has(TARGET, targetList).has(DESCRIPTION_FIELD, descriptionList).has(KEY, NAME_FIELD).build();
    // A strangeness of using name from @Service
    injectorDescriptor.removeQualifier(Named.class.getName());
    if (loader != null) {
        injectorDescriptor.setLoader(loader);
    }
    ServiceLocatorUtilities.addOneDescriptor(locator, injectorDescriptor);
}
Also used : Named(javax.inject.Named) DescriptorImpl(org.glassfish.hk2.utilities.DescriptorImpl) LinkedList(java.util.LinkedList)

Example 73 with Named

use of javax.inject.Named in project DevRing by LJYcoder.

the class MovieActivityModule method playingMovieFragment.

@ActivityScope
@Provides
@Named("playing")
MovieFragment playingMovieFragment() {
    Bundle bundle = new Bundle();
    bundle.putInt("type", MovieFragment.TYPE_PLAYING);
    MovieFragment fragment = new MovieFragment();
    fragment.setArguments(bundle);
    return fragment;
}
Also used : Bundle(android.os.Bundle) MovieFragment(com.dev.base.mvp.view.fragment.MovieFragment) Named(javax.inject.Named) ActivityScope(com.ljy.devring.di.scope.ActivityScope) Provides(dagger.Provides)

Aggregations

Named (javax.inject.Named)73 Produces (javax.enterprise.inject.Produces)32 ApplicationScoped (javax.enterprise.context.ApplicationScoped)20 Provides (com.google.inject.Provides)17 Singleton (javax.inject.Singleton)14 Properties (java.util.Properties)12 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)12 Annotation (java.lang.annotation.Annotation)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 Inject (javax.inject.Inject)5 Provides (dagger.Provides)4 Test (org.junit.Test)4 Type (java.lang.reflect.Type)3 NamedLiteral (org.apache.deltaspike.core.api.literal.NamedLiteral)3 MetadataHealthCheck (uk.gov.ida.saml.metadata.MetadataHealthCheck)3 Bundle (android.os.Bundle)2 MovieFragment (com.dev.base.mvp.view.fragment.MovieFragment)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Gson (com.google.gson.Gson)2