@Test public void resolvesSingletonMessageBodyReader() { MessageBodyReader<String> messageBodyReader = new StringEntityProvider(); componentResolver.addSingleton(messageBodyReader); verify(providers).addMessageBodyReader(messageBodyReader); }
@SuppressWarnings({"unchecked"}) public void addSingleton(Object instance) { Class clazz = instance.getClass(); if (clazz.getAnnotation(Provider.class) != null) { if (instance instanceof ContextResolver) { providers.addContextResolver((ContextResolver)instance); } if (instance instanceof ExceptionMapper) { providers.addExceptionMapper((ExceptionMapper)instance); } if (instance instanceof MessageBodyReader) { providers.addMessageBodyReader((MessageBodyReader)instance); } if (instance instanceof MessageBodyWriter) { providers.addMessageBodyWriter((MessageBodyWriter)instance); } } else if (clazz.getAnnotation(Filter.class) != null) { if (instance instanceof MethodInvokerFilter) { providers.addMethodInvokerFilter((MethodInvokerFilter)instance); } if (instance instanceof RequestFilter) { providers.addRequestFilter((RequestFilter)instance); } if (instance instanceof ResponseFilter) { providers.addResponseFilter((ResponseFilter)instance); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(instance, null); } }
RestComponentResolver { @SuppressWarnings({"unchecked"}) public void addSingleton(Object instance) { Class clazz = instance.getClass(); if (clazz.getAnnotation(Provider.class) != null) { if (instance instanceof ContextResolver) { providers.addContextResolver((ContextResolver)instance); } if (instance instanceof ExceptionMapper) { providers.addExceptionMapper((ExceptionMapper)instance); } if (instance instanceof MessageBodyReader) { providers.addMessageBodyReader((MessageBodyReader)instance); } if (instance instanceof MessageBodyWriter) { providers.addMessageBodyWriter((MessageBodyWriter)instance); } } else if (clazz.getAnnotation(Filter.class) != null) { if (instance instanceof MethodInvokerFilter) { providers.addMethodInvokerFilter((MethodInvokerFilter)instance); } if (instance instanceof RequestFilter) { providers.addRequestFilter((RequestFilter)instance); } if (instance instanceof ResponseFilter) { providers.addResponseFilter((ResponseFilter)instance); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(instance, null); } } }
RestComponentResolver { @SuppressWarnings({"unchecked"}) public void addSingleton(Object instance) { Class clazz = instance.getClass(); if (clazz.getAnnotation(Provider.class) != null) { if (instance instanceof ContextResolver) { providers.addContextResolver((ContextResolver)instance); } if (instance instanceof ExceptionMapper) { providers.addExceptionMapper((ExceptionMapper)instance); } if (instance instanceof MessageBodyReader) { providers.addMessageBodyReader((MessageBodyReader)instance); } if (instance instanceof MessageBodyWriter) { providers.addMessageBodyWriter((MessageBodyWriter)instance); } } else if (clazz.getAnnotation(Filter.class) != null) { if (instance instanceof MethodInvokerFilter) { providers.addMethodInvokerFilter((MethodInvokerFilter)instance); } if (instance instanceof RequestFilter) { providers.addRequestFilter((RequestFilter)instance); } if (instance instanceof ResponseFilter) { providers.addResponseFilter((ResponseFilter)instance); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(instance, null); } } RestComponentResolver(ResourceBinder resources, ProviderBinder providers); }
RestComponentResolver { @SuppressWarnings({"unchecked"}) public void addSingleton(Object instance) { Class clazz = instance.getClass(); if (clazz.getAnnotation(Provider.class) != null) { if (instance instanceof ContextResolver) { providers.addContextResolver((ContextResolver)instance); } if (instance instanceof ExceptionMapper) { providers.addExceptionMapper((ExceptionMapper)instance); } if (instance instanceof MessageBodyReader) { providers.addMessageBodyReader((MessageBodyReader)instance); } if (instance instanceof MessageBodyWriter) { providers.addMessageBodyWriter((MessageBodyWriter)instance); } } else if (clazz.getAnnotation(Filter.class) != null) { if (instance instanceof MethodInvokerFilter) { providers.addMethodInvokerFilter((MethodInvokerFilter)instance); } if (instance instanceof RequestFilter) { providers.addRequestFilter((RequestFilter)instance); } if (instance instanceof ResponseFilter) { providers.addResponseFilter((ResponseFilter)instance); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(instance, null); } } RestComponentResolver(ResourceBinder resources, ProviderBinder providers); @SuppressWarnings({"unchecked"}) void addSingleton(Object instance); @SuppressWarnings({"unchecked"}) void addPerRequest(Class clazz); @SuppressWarnings({"unchecked"}) void addFactory(ObjectFactory factory); }
RestComponentResolver { @SuppressWarnings({"unchecked"}) public void addSingleton(Object instance) { Class clazz = instance.getClass(); if (clazz.getAnnotation(Provider.class) != null) { if (instance instanceof ContextResolver) { providers.addContextResolver((ContextResolver)instance); } if (instance instanceof ExceptionMapper) { providers.addExceptionMapper((ExceptionMapper)instance); } if (instance instanceof MessageBodyReader) { providers.addMessageBodyReader((MessageBodyReader)instance); } if (instance instanceof MessageBodyWriter) { providers.addMessageBodyWriter((MessageBodyWriter)instance); } } else if (clazz.getAnnotation(Filter.class) != null) { if (instance instanceof MethodInvokerFilter) { providers.addMethodInvokerFilter((MethodInvokerFilter)instance); } if (instance instanceof RequestFilter) { providers.addRequestFilter((RequestFilter)instance); } if (instance instanceof ResponseFilter) { providers.addResponseFilter((ResponseFilter)instance); } } else if (clazz.getAnnotation(Path.class) != null) { resources.addResource(instance, null); } } RestComponentResolver(ResourceBinder resources, ProviderBinder providers); @SuppressWarnings({"unchecked"}) void addSingleton(Object instance); @SuppressWarnings({"unchecked"}) void addPerRequest(Class clazz); @SuppressWarnings({"unchecked"}) void addFactory(ObjectFactory factory);  }