本文整理匯總了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);
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
示例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) {
//
}
};
}
示例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;
}
};
}
}
示例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;
}
};
}
}
示例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;
}
示例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));
}
示例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;
}
示例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) { }
};
}
示例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;
}
示例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));
}
示例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();
}
示例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");
}
});
}