當前位置: 首頁>>代碼示例>>Java>>正文


Java Factory類代碼示例

本文整理匯總了Java中org.glassfish.hk2.api.Factory的典型用法代碼示例。如果您正苦於以下問題:Java Factory類的具體用法?Java Factory怎麽用?Java Factory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Factory類屬於org.glassfish.hk2.api包,在下文中一共展示了Factory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override
    public void run(T configuration, Environment environment) {
        final HazelcastSessionConfig hazelcastSessionConfig = getHazelcastSessionConfig(configuration);

        final Class<? extends Factory<SessionsStore>> sessionsStoreFactoryClass = hazelcastSessionConfig.getSessionsStoreFactoryClass();
        environment.jersey().register(new AbstractBinder() {
            @Override
            protected void configure() {
                bindFactory(sessionsStoreFactoryClass).to(SessionsStore.class).in(Singleton.class);
                bind(hazelcastSessionConfig).to(HazelcastSessionConfig.class);
                bind(SessionObjectResolver.class)
                        .to(new TypeLiteral<InjectionResolver<Session>>() {
                        })
                        .in(Singleton.class);
            }
        });
//        environment.lifecycle().manage(new HazelcastInstanceManager(hazelcastInstance));
        environment.jersey().register(SetSessionIdResponseFilter.class);
    }
 
開發者ID:martindow,項目名稱:dropwizard-hazelcast-session,代碼行數:20,代碼來源:HazelcastSessionBundle.java

示例2: createValueFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override
protected Factory<?> createValueFactory(Parameter parameter) {

    if (!parameter.isAnnotationPresent(Prop.class)) {
        return null;
    }

    String parameterName = parameter.getSourceName();
    if (parameterName == null || parameterName.length() == 0) {
        // Invalid parameter name
        return null;
    }

    MultivaluedParameterExtractor e = get(parameter);
    if (e == null) {
        return null;
    }

    PropertyFactory factory = new PropertyFactory(e, parameter, i18nEnabled);
    serviceLocator.inject(factory);
    return factory;
}
 
開發者ID:psamsotha,項目名稱:jersey-properties,代碼行數:23,代碼來源:PropertiesValueFactoryProvider.java

示例3: install

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public void install(final AbstractBinder binder, final Injector injector, final Class<Object> type) {
    if (is(type, Factory.class)) {
        // register factory directly (without wrapping)
        bindFactory(binder, injector, type);

    } else {
        // support multiple extension interfaces on one type
        final Set<Class<?>> extensions = Sets.intersection(EXTENSION_TYPES,
                GenericsResolver.resolve(type).getGenericsInfo().getComposingTypes());
        if (!extensions.isEmpty()) {
            for (Class<?> ext : extensions) {
                bindSpecificComponent(binder, injector, type, ext);
            }
        } else {
            // no known extension found
            bindComponent(binder, injector, type);
        }
    }
}
 
開發者ID:xvik,項目名稱:dropwizard-guicey,代碼行數:22,代碼來源:JerseyProviderInstaller.java

示例4: bindFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
/**
 * Binds hk {@link Factory}. If bean is {@link HK2Managed} then registered directly as
 * factory. Otherwise register factory through special "lazy bridge" to delay guice factory bean instantiation.
 * Also registers factory directly (through wrapper to be able to inject factory by its type).
 *
 * @param binder   hk binder
 * @param injector guice injector
 * @param type     factory to bind
 * @param <T>      actual type (used to workaround type checks)
 * @see ru.vyarus.dropwizard.guice.module.jersey.support.LazyGuiceFactory
 * @see ru.vyarus.dropwizard.guice.module.jersey.support.GuiceComponentFactory
 */
@SuppressWarnings("unchecked")
public static <T> void bindFactory(final AbstractBinder binder, final Injector injector, final Class<?> type) {
    // resolve Factory<T> actual type to bind properly
    final Class<T> res = (Class<T>) GenericsResolver.resolve(type).type(Factory.class).generic(0);
    if (isHK2Managed(type)) {
        binder.bindFactory((Class<Factory<T>>) type)
                .to(res)
                .in(Singleton.class);
    } else {
        binder.bindFactory(new LazyGuiceFactory(injector, type))
                .to(res);
        // binding factory type to be able to autowire factory by name
        binder.bindFactory(new GuiceComponentFactory<>(injector, type))
                .to(type);
    }
}
 
開發者ID:xvik,項目名稱:dropwizard-guicey,代碼行數:29,代碼來源:JerseyBinding.java

示例5: instanceFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
private <T> Factory<T> instanceFactory(final T object) {
	return new Factory<T>() {

		@Override
		public T provide() {
			return object;
		}

		@Override
		public void dispose(T instance) {
			//
		}
	};
}
 
開發者ID:Mercateo,項目名稱:rest-jersey-utils,代碼行數:15,代碼來源:TestBinder.java

示例6: createValueFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override
protected Factory<RequestRateLimiterFactory> createValueFactory(final Parameter parameter) {
    final RateLimiting annotation = parameter.getAnnotation(RateLimiting.class);
    if (null == annotation) {
        return null;
    } else {
        return new AbstractContainerRequestValueFactory<RequestRateLimiterFactory>() {
            public RequestRateLimiterFactory provide() {
                return requestRateLimiterFactory;
            }
        };
    }
}
 
開發者ID:mokies,項目名稱:ratelimitj,代碼行數:14,代碼來源:RateLimitBundle.java

示例7: createValueFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override
protected Factory<?> createValueFactory(final Parameter parameter) {
    final RateLimiting annotation = parameter.getAnnotation(RateLimiting.class);
    if (null == annotation) {
        return null;
    } else {
        return new AbstractContainerRequestValueFactory<RequestRateLimiterFactory>() {
            public RequestRateLimiterFactory provide() {
                return requestRateLimiterFactory;
            }
        };
    }
}
 
開發者ID:mokies,項目名稱:ratelimitj,代碼行數:14,代碼來源:RateLimit429EnforcerFilterTest.java

示例8: createValueFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override
    protected Factory<?> createValueFactory(Parameter parameter) {

        LOGGER.debug("{}", parameter);
//        parameter.getSourceName()
        JsonParamValueFactory factory = new JsonParamValueFactory(parameter);
        getLocator().inject(factory);
        return factory;
    }
 
開發者ID:protoxme,項目名稱:protox-webapp-archetype,代碼行數:10,代碼來源:JsonParamValueFactoryProvider.java

示例9: bindFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Beta
public <U> ServiceBindingBuilder<U> bindFactory(
    @NonNull Class<? extends Factory<U>> factoryClass, Class<? extends Annotation> factoryScope
) {
    finishBinding();
    return (ServiceBindingBuilder<U>) (activeBuilder = BindingBuilderFactory.newFactoryBinder(factoryClass, factoryScope));
}
 
開發者ID:baharclerode,項目名稱:dropwizard-hk2,代碼行數:8,代碼來源:HK2Bundle.java

示例10: createValueFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override
protected Factory<?> createValueFactory(Parameter parameter) {
    if (parameter.isAnnotationPresent(Pac4JProfileManager.class)) {
        if (ProfileManager.class.isAssignableFrom(parameter.getRawType())) {
            return manager.get();
        }

        throw new IllegalStateException("Cannot inject a Pac4J profile manager into a parameter of type "
                + parameter.getRawType().getName());
    }

    if (parameter.isAnnotationPresent(Pac4JProfile.class)) {
        if (CommonProfile.class.isAssignableFrom(parameter.getRawType())) {
            return profile.get();
        }

        if (Optional.class.isAssignableFrom(parameter.getRawType())) {
            List<ClassTypePair> ctps = ReflectionHelper.getTypeArgumentAndClass(parameter.getRawType());
            ClassTypePair ctp = (ctps.size() == 1) ? ctps.get(0) : null;
            if (ctp == null || CommonProfile.class.isAssignableFrom(ctp.rawClass())) {
                return optProfile.get();
            }
        }

        throw new IllegalStateException(
                "Cannot inject a Pac4J profile into a parameter of type " + parameter.getRawType().getName());
    }

    return null;
}
 
開發者ID:pac4j,項目名稱:jax-rs-pac4j,代碼行數:31,代碼來源:Pac4JValueFactoryProvider.java

示例11: createValueFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override
protected Factory<String> createValueFactory(Parameter parameter) {
	return new Factory<String>() {
		@Override
		public String provide() {
			return "hello world";
		}

		@Override
		public void dispose(String instance) {  }
	};
}
 
開發者ID:Maddoc42,項目名稱:JaxRs2Retrofit,代碼行數:13,代碼來源:CustomAnnotationTest.java

示例12: createValueFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override protected Factory<?> createValueFactory(final Parameter parameter) {
  final Class<?> classType = parameter.getRawType();
  final Auth auth = parameter.getAnnotation(Auth.class);

  if (auth == null) {
    return null;
  }

  if (classType.equals(Client.class)) {
    return new AbstractContainerRequestValueFactory<Client>() {
      @Override public Client provide() {
        return clientAuthFactory.provide(getContainerRequest());
      }
    };
  }

  if (classType.equals(AutomationClient.class)) {
    return new AbstractContainerRequestValueFactory<AutomationClient>() {
      @Override public AutomationClient provide() {
        return automationClientAuthFactory.provide(getContainerRequest());
      }
    };
  }

  if (classType.equals(User.class)) {
    return new AbstractContainerRequestValueFactory<User>() {
      @Override public User provide() {
        return userAuthFactory.provide(getContainerRequest());
      }
    };
  }

  return null;
}
 
開發者ID:square,項目名稱:keywhiz,代碼行數:35,代碼來源:AuthResolver.java

示例13: createValueFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override
protected Factory<?> createValueFactory(Parameter parameter) {
    Class<?> classType = parameter.getRawType();

    if (classType == null || (!classType.equals(Configuration.class))) {
        return null;
    }

    return new ConfigurationFactory(configuration, dataSource, multiTenantConnectionProvider,
            parameter.getAnnotation(JooqConfiguration.class));
}
 
開發者ID:tbugrara,項目名稱:dropwizard-jooq,代碼行數:12,代碼來源:ConfigurationFactoryProvider.java

示例14: createValueFactory

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
@Override
protected Factory<?> createValueFactory(Parameter parameter)
{

  Class<?> classType = parameter.getRawType();

  if (classType == null || (!classType.equals(UnverifiedCredentials.class)))
  {
    return null;
  }

  return new MyContextValueFactory();

}
 
開發者ID:zourzouvillys,項目名稱:graphql,代碼行數:15,代碼來源:AuthContainerRequestFilter.java

示例15: SwaggerResourceConfig

import org.glassfish.hk2.api.Factory; //導入依賴的package包/類
public SwaggerResourceConfig() {
    register(new AbstractBinder() {
        @Override
        protected void configure() {
            bindFactory(new Factory<Map<String, Swagger>>() {

                @Override
                public Map<String, Swagger> provide() {
                    EntityDictionary dictionary = new EntityDictionary(Maps.newHashMap());

                    dictionary.bindEntity(Book.class);
                    dictionary.bindEntity(Author.class);
                    dictionary.bindEntity(Publisher.class);
                    Info info = new Info().title("Test Service").version("1.0");

                    SwaggerBuilder builder = new SwaggerBuilder(dictionary, info);
                    Swagger swagger = builder.build();

                    Map<String, Swagger> docs = new HashMap<>();
                    docs.put("test", swagger);
                    return docs;
                }

                @Override
                public void dispose(Map<String, Swagger> instance) {
                    //NOP
                }
            }).to(new TypeLiteral<Map<String, Swagger>>() {
            }).named("swagger");
        }
    });
}
 
開發者ID:yahoo,項目名稱:elide,代碼行數:33,代碼來源:SwaggerResourceConfig.java


注:本文中的org.glassfish.hk2.api.Factory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。