Java 类javax.ws.rs.ext.ParamConverterProvider 实例源码

项目:minijax    文件:MinijaxProviders.java   
@SuppressWarnings("unchecked")
public void register(final Class<?> c) {
    if (MessageBodyReader.class.isAssignableFrom(c)) {
        readers.add((Class<MessageBodyReader<?>>) c, MediaTypeUtils.parseMediaTypes(c.getAnnotation(Consumes.class)));
    }

    if (MessageBodyWriter.class.isAssignableFrom(c)) {
        writers.add((Class<MessageBodyWriter<?>>) c, MediaTypeUtils.parseMediaTypes(c.getAnnotation(Produces.class)));
    }

    if (ExceptionMapper.class.isAssignableFrom(c)) {
        exceptionMappers.add((Class<ExceptionMapper<?>>) c, MediaTypeUtils.parseMediaTypes(c.getAnnotation(Produces.class)));
    }

    if (ParamConverterProvider.class.isAssignableFrom(c)) {
        paramConverterProviders.add((ParamConverterProvider) application.get(c));
    }
}
项目:microprofile-rest-client    文件:AdditionalRegistrationTest.java   
@Test
public void shouldRegisterAMultiTypedProviderInstanceWithPriorities() {
    MultiTypedProvider provider = new MultiTypedProvider();
    Map<Class<?>, Integer> priorities = new HashMap<>();
    priorities.put(ClientRequestFilter.class, 500);
    priorities.put(ClientResponseFilter.class, 501);
    priorities.put(MessageBodyReader.class, 502);
    priorities.put(MessageBodyWriter.class, 503);
    priorities.put(ReaderInterceptor.class, 504);
    priorities.put(WriterInterceptor.class, 505);
    priorities.put(ResponseExceptionMapper.class, 506);
    priorities.put(ParamConverterProvider.class, 507);
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(provider, priorities);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
    assertTrue(configuration.isRegistered(provider), MultiTypedProvider.class + " should be registered");
    Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class);
    assertEquals(contracts.size(), priorities.size(),
        "There should be "+priorities.size()+" provider types registered");
    for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) {
        Integer contractPriority = contracts.get(priority.getKey());
        assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue());
    }
}
项目:microprofile-rest-client    文件:AdditionalRegistrationTest.java   
@Test
public void shouldRegisterAMultiTypedProviderClassWithPriorities() {
    Map<Class<?>, Integer> priorities = new HashMap<>();
    priorities.put(ClientRequestFilter.class, 500);
    priorities.put(ClientResponseFilter.class, 501);
    priorities.put(MessageBodyReader.class, 502);
    priorities.put(MessageBodyWriter.class, 503);
    priorities.put(ReaderInterceptor.class, 504);
    priorities.put(WriterInterceptor.class, 505);
    priorities.put(ResponseExceptionMapper.class, 506);
    priorities.put(ParamConverterProvider.class, 507);
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(MultiTypedProvider.class, priorities);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
    Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class);
    assertEquals(contracts.size(), priorities.size(),
        "There should be "+priorities.size()+" provider types registered");
    for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) {
        Integer contractPriority = contracts.get(priority.getKey());
        assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue());
    }
}
项目:ameba    文件:RsAddonFeature.java   
@Override
protected void configure() {
    bind(OptionsMethodProcessor.DefaultOptionsResponseGenerator.class)
            .to(OptionsResponseGenerator.class)
            .in(Singleton.class);

    bind(OptionsMethodProcessor.class)
            .to(ModelProcessor.class)
            .in(Singleton.class);

    bind(ParamConverters.TypeFromStringEnum.class)
            .to(ParamConverterProvider.class)
            .in(Singleton.class).ranked(10);

    bind(ParamConverters.DateProvider.class)
            .to(ParamConverterProvider.class)
            .in(Singleton.class).ranked(10);

    bind(ParamConverters.BooleanProvider.class)
            .to(ParamConverterProvider.class)
            .in(Singleton.class).ranked(10);
}
项目:minijax    文件:MinijaxProviders.java   
public <T> ParamConverter<T> getParamConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
    for (final ParamConverterProvider provider : paramConverterProviders) {
        final ParamConverter<T> converter = provider.getConverter(rawType, genericType, annotations);
        if (converter != null) {
            return converter;
        }
    }
    return null;
}
项目:microprofile-rest-client    文件:AdditionalRegistrationTest.java   
@Test
public void shouldRegisterAMultiTypedProviderInstance() {
    MultiTypedProvider provider = new MultiTypedProvider();
    Class[] providerTypes = {ClientRequestFilter.class, ClientResponseFilter.class,
        MessageBodyReader.class, MessageBodyWriter.class, ReaderInterceptor.class, WriterInterceptor.class,
        ResponseExceptionMapper.class, ParamConverterProvider.class};
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(provider, providerTypes);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
    assertTrue(configuration.isRegistered(provider), MultiTypedProvider.class + " should be registered");
    assertEquals(configuration.getContracts(MultiTypedProvider.class).size(), providerTypes.length,
        "There should be "+providerTypes.length+" provider types registered");
}
项目:microprofile-rest-client    文件:AdditionalRegistrationTest.java   
@Test
public void shouldRegisterAMultiTypedProviderClass() {
    Class[] providerTypes = {ClientRequestFilter.class, ClientResponseFilter.class,
        MessageBodyReader.class, MessageBodyWriter.class, ReaderInterceptor.class, WriterInterceptor.class,
        ResponseExceptionMapper.class, ParamConverterProvider.class};
    RestClientBuilder builder = RestClientBuilder.newBuilder().register(MultiTypedProvider.class, providerTypes);
    Configuration configuration = builder.getConfiguration();
    assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
    assertEquals(configuration.getContracts(MultiTypedProvider.class).size(), providerTypes.length,
        "There should be "+providerTypes.length+" provider types registered");
}
项目:tomee    文件:RESTService.java   
private static <T> boolean isProvider(final Class<T> clazz) {
    return MessageBodyReader.class.isAssignableFrom(clazz) ||
            MessageBodyWriter.class.isAssignableFrom(clazz) ||
            ParamConverter.class.isAssignableFrom(clazz) ||
            ContainerRequestFilter.class.isAssignableFrom(clazz) ||
            ContainerResponseFilter.class.isAssignableFrom(clazz) ||
            ReaderInterceptor.class.isAssignableFrom(clazz) ||
            WriterInterceptor.class.isAssignableFrom(clazz) ||
            ParamConverterProvider.class.isAssignableFrom(clazz) ||
            ContextResolver.class.isAssignableFrom(clazz) ||
            new MetaAnnotatedClass<>(clazz).isAnnotationPresent(Provider.class);
}
项目:dropwizard-vavr    文件:OptionParamBinder.java   
@Override
protected void configure() {
    // Param converter providers
    bind(OptionParamConverterProvider.class).to(ParamConverterProvider.class).in(Singleton.class);
}
项目:dropwizard-vavr    文件:LazyParamBinder.java   
@Override
protected void configure() {
    // Param converter providers
    bind(LazyParamConverterProvider.class).to(ParamConverterProvider.class).in(Singleton.class);
}
项目:minijax    文件:MinijaxProviders.java   
private static List<ParamConverterProvider> getDefaultParamConverterProviders() {
    return Collections.singletonList(new UuidParamConverterProvider());
}
项目:nexus-public    文件:SisuResteasyProviderFactory.java   
/**
 * Unregisters a @Provider type from this factory.
 */
public void removeRegistrations(final Class<?> type) {
  checkNotNull(type);

  log.debug("Removing registrations for: {}", type.getName());

  classContracts.remove(type);

  removeInstancesOf(type, providerInstances);
  providerClasses.remove(type);

  if (ExceptionMapper.class.isAssignableFrom(type)) {
    removeInstancesOf(type, exceptionMappers.values());
  }
  else if (MessageBodyReader.class.isAssignableFrom(type)) {
    clearInstancesOf(type, clientMessageBodyReaders, DUMMY_READER);
    clearInstancesOf(type, serverMessageBodyReaders, DUMMY_READER);
  }
  else if (MessageBodyWriter.class.isAssignableFrom(type)) {
    clearInstancesOf(type, clientMessageBodyWriters, DUMMY_WRITER);
    clearInstancesOf(type, serverMessageBodyWriters, DUMMY_WRITER);
  }
  else if (ContextResolver.class.isAssignableFrom(type)) {
    Type[] args = Types.getActualTypeArgumentsOfAnInterface(type, ContextResolver.class);
    contextResolvers.remove(Types.getRawType(args[0]));
  }
  else if (Feature.class.isAssignableFrom(type)) {
    removeInstancesOf(type, featureInstances);
    removeInstancesOf(type, enabledFeatures);
    featureClasses.remove(type);
  }
  else if (DynamicFeature.class.isAssignableFrom(type)) {
    removeInstancesOf(type, clientDynamicFeatures);
    removeInstancesOf(type, serverDynamicFeatures);
  }
  else if (ParamConverterProvider.class.isAssignableFrom(type)) {
    removeInstancesOf(type, paramConverterProviders);
  }
  else if (StringConverter.class.isAssignableFrom(type)) {
    removeInstancesOf(type, stringConverters.values());
  }
  else if (StringParameterUnmarshaller.class.isAssignableFrom(type)) {
    stringParameterUnmarshallers.values().remove(type);
  }
  else {
    log.warn("Unable to remove registrations for: {}", type.getName());
  }
}
项目:dropwizard-java8    文件:OptionalParamBinder.java   
@Override
protected void configure() {
    // Param converter providers
    bind(OptionalParamConverterProvider.class).to(ParamConverterProvider.class).in(Singleton.class);
}