當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。