当前位置: 首页>>代码示例>>Java>>正文


Java Providers.getContextResolver方法代码示例

本文整理汇总了Java中javax.ws.rs.ext.Providers.getContextResolver方法的典型用法代码示例。如果您正苦于以下问题:Java Providers.getContextResolver方法的具体用法?Java Providers.getContextResolver怎么用?Java Providers.getContextResolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.ext.Providers的用法示例。


在下文中一共展示了Providers.getContextResolver方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: lookupResource

import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
/**
 * Lookup a resource of given <code>resourceType</code> type, either using a suitable {@link ContextResolver} if
 * <code>providers</code> is not <code>null</code> and a {@link ContextResolver} for given <code>resourceType</code>
 * is available, or trying to obtain the resource from {@link Context} using given <code>resourceType</code> as
 * context resource key.
 * @param <R> Resource type
 * @param caller Caller class
 * @param resourceType Resource type to lookup (not null)
 * @param providers JAX-RS {@link Providers}, if available
 * @return Resource instance, or an empty optional if not available
 */
public static <R> Optional<R> lookupResource(Class<?> caller, Class<R> resourceType, Providers providers) {
	ObjectUtils.argumentNotNull(resourceType, "Resource type must be not null");

	R resource = null;

	// try to use a ContextResolver, if available
	ContextResolver<R> resolver = providers.getContextResolver(resourceType, null);
	if (resolver != null) {
		resource = resolver.getContext(caller);
	}

	if (resource == null) {
		// lookup in context
		resource = Context.get()
				.resource(resourceType,
						(caller != null) ? caller.getClassLoader() : ClassUtils.getDefaultClassLoader())
				.orElse(null);
	}

	return Optional.ofNullable(resource);
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:33,代码来源:ResourceUtils.java

示例2: testLocateGensonContextResolver

import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
@Test
public void testLocateGensonContextResolver() {
    Providers providers = instance(Providers.class);

    RuntimeDelegate.setInstance(new DefaultRuntimeDelegate());

    ContextResolver contextResolver = providers.getContextResolver(Genson.class, MediaType.APPLICATION_JSON_TYPE);

    assertNotNull(contextResolver);
    assertEquals(TestGensonContextResolver3.class, contextResolver.getClass());
}
 
开发者ID:geetools,项目名称:geeMVC-Java-MVC-Framework,代码行数:12,代码来源:JaxRsResolverTest.java

示例3: testLocateObjectContextResolver

import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
@Test
public void testLocateObjectContextResolver() {
    Providers providers = instance(Providers.class);

    RuntimeDelegate.setInstance(new DefaultRuntimeDelegate());

    ContextResolver contextResolver = providers.getContextResolver(Person.class, MediaType.APPLICATION_JSON_TYPE);

    assertNotNull(contextResolver);
    assertEquals(TestGensonContextResolver6.class, contextResolver.getClass());
}
 
开发者ID:geetools,项目名称:geeMVC-Java-MVC-Framework,代码行数:12,代码来源:JaxRsResolverTest.java

示例4: testLocateApplicationContextResolver

import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
@Test
public void testLocateApplicationContextResolver() {
    Providers providers = instance(Providers.class);

    RuntimeDelegate.setInstance(new DefaultRuntimeDelegate());

    ContextResolver contextResolver = providers.getContextResolver(Application.class, MediaType.APPLICATION_JSON_TYPE);

    assertNotNull(contextResolver);
    assertEquals(TestApplicationContextResolver.class, contextResolver.getClass());
}
 
开发者ID:geetools,项目名称:geeMVC-Java-MVC-Framework,代码行数:12,代码来源:JaxRsResolverTest.java

示例5: locateFactory

import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
public static SpearalFactory locateFactory(Configuration configuration, Providers providers) {
	ContextResolver<SpearalFactory> resolver = providers.getContextResolver(SpearalFactory.class, APPLICATION_SPEARAL_TYPE);
	if (resolver != null)
		return resolver.getContext(SpearalFactory.class);
	
	for (Object instance : configuration.getInstances()) {
		if (instance instanceof SpearalFactory)
			return (SpearalFactory)instance;
	}
	
	throw new RuntimeException("Could not locate SpearalFactory in JAX-RS context");
}
 
开发者ID:spearal,项目名称:spearal-jaxrs,代码行数:13,代码来源:SpearalJaxrs.java

示例6: resolveFromContext

import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
public static <T> T resolveFromContext(Providers providers, Class<T> clazz, MediaType mediaType, Class<?> type) {
  ContextResolver<T> contextResolver = providers.getContextResolver(clazz, mediaType);

  if (contextResolver == null) {
    throw new RestException("No context resolver found for class " + clazz.getName());
  }

  return contextResolver.getContext(type);
}
 
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:10,代码来源:ProvidersUtil.java

示例7: PersonMessageBodyReader

import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
public PersonMessageBodyReader(@Context Application application, @Context UriInfo uriInfo, @Context HttpHeaders httpHeaders, @Context Providers providers) {
    ContextResolver<Genson> gensonResolver = providers.getContextResolver(Genson.class, MediaType.APPLICATION_JSON_TYPE);
    gensonResolver.getContext(Genson.class);
}
 
开发者ID:geetools,项目名称:geeMVC-Java-MVC-Framework,代码行数:5,代码来源:PersonMessageBodyReader.java

示例8: locate

import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
public static ServiceRepository locate(Providers providers) {
    ContextResolver<ServiceRepository> resolver = providers.getContextResolver(ServiceRepository.class, MediaType.WILDCARD_TYPE);
    return resolver.getContext(null);
}
 
开发者ID:pivotal,项目名称:delboy,代码行数:5,代码来源:ServiceRepositoryProvider.java

示例9: getContextFromProvider

import javax.ws.rs.ext.Providers; //导入方法依赖的package包/类
private static DiscoveryContext<String> getContextFromProvider(Providers providers)
{
    ContextResolver<DiscoveryContext> contextResolver = providers.getContextResolver(DiscoveryContext.class, MediaType.WILDCARD_TYPE);
    //noinspection unchecked
    return contextResolver.getContext(DiscoveryContext.class);
}
 
开发者ID:apache,项目名称:curator,代码行数:7,代码来源:StringDiscoveryResource.java


注:本文中的javax.ws.rs.ext.Providers.getContextResolver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。